0

Rolling with a similar example: If you have Companies and companies have Divisions and divisions have Employees, when you make a GET request for a company how do you decide what data to embed? For example you could return a Company with nested Divisions and People. Or, you could make 3 separate calls.

I've been using the GitHub API a bit and they seem to embed some data providing its not an array. For example, when you request a repo it may have the owner embedded but not issues and pull requests. How did they decide on this?

Also, it seems like, depending on your data store SQL vs NoSQL mileage may vary here.

Found this example m but its not quite the same.

Jason Leach
  • 3,889
  • 7
  • 37
  • 54
  • it's gonna be hard to answer this because it's so context dependent. Most people tend to go towards "1 type of entity per request` and only add more data if there are strong reasons to do so. I think that's a reasonable rule of thumb. – Evert May 07 '20 at 03:38

1 Answers1

0

when you make a GET request for a company how do you decide what data to embed?

I think your asking something like "when designing a resource, how do you decide what information belongs in the representation, and what information is linked?"

An answer to that is to pay attention to the fact that caching happens at the resource level -- the target-uri is the cache key. When we invalidate a resource, we invalidate all of its representations.

An implication here is that we want the caching policy of the resource to be favorable for all of the information included in the representation.

Mixing data that changes minute-by-minute with data that has an expected half life of a year makes it difficult to craft a sensible caching policy. So it might make more sense to carve the information into piles with similar life cycles, and have a separate resource for each.

Consider a website like stack overflow: the branding (logo, style sheets, images) doesn't change very often; the page contents (questions, answers, comments) change at a higher cadence. The total network bandwidth consumed is probably considerably lower if you link to the big, slowly changing design elements.

(Also, once you do use links, you have the ability to move the different resources independently - moving content to a CDN, routing high and low priority requests differently, and so on).

Community
  • 1
  • 1
VoiceOfUnreason
  • 52,766
  • 5
  • 49
  • 91