Score:0

How can I get specific fields from user object in the REST API?

al flag

I have a question about retrieving fields from the user object using REST in Drupal 8. When i am logged in into Drupal i can use the following GET call too retrieve the user object:

http://localhost:8081/user/2?_format=json

This will return a json response with all the fields of this user. I only want to retrieve 3 fields and not the whole object.

How can i set some specific fields too return and not all the fields?

4uk4 avatar
cn flag
If this is the only thing you want to get via JSON then write a custom JSON controller. If this is only the start of a much bigger project then look for a different web service implementation. See https://dri.es/headless-cms-rest-vs-jsonapi-vs-graphql
Thomas Crawford avatar
al flag
Thanks @4k4, this is the only thing so i will build a JSON controller.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.