How to get user and content data with a single request


#1

I’m a beginner to JSON API (using Drupal, specifically Acquia Reservoir, with a Vue/Axios front-end). I am able to get an article node, which contains a user id in a relationships object. But I would like to receive author information such as full name and profile link along with this user ID. I would hope that I don’t need to make a seperate request for this, or is that the way it’s done?

I am looking all over on both Drupal docs, JSON API, Axios docs, Vue docs etc. for an answer to this, and must be missing something obvious. Can someone help?

Thanks.

Marc Eliot Stein


#2

Hi,

as I understand the spec, the inclusion of related documents is completely up to the server. I am not familiar with Drupal.

I have implemented your use case like this:

The client does one request (with or without an include url query param) and the server retrieves the (in your case) article from the database. Now if the include param is given or the server returns included resources by default, it will now retrieve the related documents (user) from the database and enrich your article resource with these related resources. Now the client returns the composite resource.

You won’t find an answer in either the JSON API docs, Vue docs or axios docs. I am not familiar with Drupal, but your best bet would be to look at the docs and check if fetching of related resources is supported.

Jannik


#3

Thanks a lot! This makes sense.