Reduce Calls to Details API

Viewed 33

if i developed API that return list of offers(v1/offers), or it return details for specific offer(v1/offers/12345), is it a good practice to return all offers details when calling /offers list to mobile? to Reduce calls for Offer Details API?, so instead of calling v1/offers/12345, all details for 12345 will be returned when calling v1/offers thanks

1 Answers

REST does not dictate how to solve this.

It is perfectly okay for a REST API to declare a query parameter or HTTP header by which the API client can declare the required level of detail (e.g. minimal / compact / detailed).

This prevents underfetching (where the client first gets the list of offer IDs and then has to fetch every individual offer) as well as overfetching (returning details of each offer that the client wasn't even interested in) but it requires the API client to take this decision. Whether that is "good" or not depends on how many API clients you have and how different their usage requirements are.

Related