News for hackers. Stuff that matters.
Re:Use links not keys to represent relationships in APIs by jeltz on Sunday May 12, 2019 @09:05AM (#19891625)
Do I misunderstand you or do you suggest that the customer object should include the list of all invoices? That does not scale. Imagine if it is something more common like transactions where a user can have made thousands or tens of thousands.
Re:Use links not keys to represent relationships in APIs by randallsquared on Sunday May 12, 2019 @09:28AM (#19891751)
An API should usually prioritize ease of development over faithfully exposing database or architecture internals.

However, you can have it both ways: in the customer response, use

    "invoices": "/customer/7sn2J/invoices"
and have the server 307 redirect to "/invoices?customer=7sn2J", or whatever you prefer.
Re:Use links not keys to represent relationships in APIs by rich-tea on Monday May 13, 2019 @07:54AM (#19898332)
It can contain a link to the list of all invoices. So you could have /customer/<cid>/invoice which lists all invoices for the customer which are actually just links of the form /customer/<cid>/invoice/<iid>