Skip to content

How do you handle relations / nested objects? #15

Answered by benbjohnson
fr3fou asked this question in Q&A
Discussion options

You must be logged in to vote

When do you return nested objects / relations? Do you always return them? Do you expose query params that help you do that (kinda like a self-made-GraphQL)

I typically start with returning nested objects & relations. Usually just parent relationships (e.g. attaching a Customer onto a returned Order object). Most APIs only have one or two endpoints that are called a lot so I'll optimize those with a query param if I really need to restrict the returned data.

Would you return nested objects / relations when accessing an endpoint which returns an array? (i.e in a shop app /categories/ also returning all the products in each category). In my case if I don't - I will end up with the N+1 pro…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fr3fou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants