Should offset and limit be in API response body?

Viewed 1044

Pagination with Limit and Offset is commonly used to return large data sets from an API.

When an API request contains Limit and Offset values, should the response body also include the same Limit and Offset values or are those fields redundant and unnecessary in response?

Many examples show Limit and Offset included in the response body. Is this best practice and for what purpose if the requester already has this information?

Example Request: baseUrl.com/api/data?limit=50&offset=100

Example Response:

{
  "totalResults": 100000,
  "limit": 50,   // is this best practice or redundant?
  "offset": 100, // is this best practice or redundant?
  "count": 50,
  "items": [ ]  
}
1 Answers

Some APIs have default values set for Offset and Limit. If the requester doesn't feed those values in the request, the response still returns items with the default Offset and Limit. Hence I would like the response to have the current values of Offset and Limit, so it will not confuse the requester.

Related