-
Notifications
You must be signed in to change notification settings - Fork 73
Pagination
An API of Ice And Fire provides a lot of data about the world of Westeros. To prevent our servers from getting cranky, the API will automatically paginate the responses. You will learn how to create requests with pagination parameters and consume the response.
- Information about the pagination is included in the Link header
- Page numbering is 1-based
- You can specify how many items you want to receive per page, the maximum is 50
You specify which page you want to access with the ?page parameter, if you don't provide the ?page parameter the first page will be returned. You can also specify the size of the page with the ?pageSize parameter, if you don't provide the ?pageSize parameter the default size of 10 will be used.
Let's make a request for the first page of characters with a page size of 10. Since we're only interested in the pagination information we provide the -I parameter to say that we only care about the headers.
$ curl -I "https://www.anapioficeandfire.com/api/characters?page=1&pageSize=10"
Response
Link: <https://www.anapioficeandfire.com/api/characters?page=2&pageSize=10>; rel="next", <https://www.anapioficeandfire.com/api/characters?page=1&pageSize=10>; rel="first", <https://www.anapioficeandfire.com/api/characters?page=214&pageSize=10>; rel="last"
-
next- Next page of results -
prev- Previous page of results -
first- First page of results -
last- Last page of results
These links can then be used to navigate to other pages of results.