We are creating REST API which will be consume by Web and Mobile users.
My uestion is do we need to consider user interface before designing JSON structure?
We have one resource Company, and Company has multiple customers with its experiances.
we created API
to fetch list of customers for particular company. In response of API, we are sending list of customers with basic detail like (id, name, address, email, phone).
Is that a best practice to send customer experiences with customer detail?
currently while fetching customers we are sending only basic detail of customers without their experiences.
when we reffer user interface for mobile and web its showing customer's experience with customer detail in customer listing screen.
so now is that a best practice if we make multiple small rest calls to get other information ?
please can you guide us.
Thank you in advance.
I do not regard sending various details together with main data by default as a good practice. Instead, use some option with name like
_with to list all child entities you want to get in an API response. For your example it might be something like:
Usually I try to map
_with items to my domain model (
Customer is a main entity,
Purchase are related to it).
I do not recommend using small REST calls to fetch details because of performance reasons. REST call is an expensive thing.