Skip to main content
Tweeted twitter.com/StackSoftEng/status/1371159205512613888
Source Link

One API endpoint for each frontend "need"

Let's say our web application handles "orders". An order can be displayed in several different pages of our web app, on each one, in a very different way.

For example: in page A, it shows just very basic information about the order (like it's date and total value). In page B, it shows also information about the user requesting the order. In page C, it shows all that + a lot of other details.

Should I have 3 different API endpoints to provide an order, one for each page, providing only the information the page will need, or should I have just one, providing all the possible information about an order?

If I have just one endpoint, it will return a lot of unecessary information to some pages, and also will decrease performance (bigger queries, joins with other tables, etc.).

But I don't know if it is a bad practice to create one endpoint for each frontend "need".