Pagination in a RESTful API


#1

I am new to Ember and am using the RESTful API pokeapi.co to learn. This API has 949 pokemons and has filters to list 20 per page.

API URL https://pokeapi.co/api/v2/pokemon/

count: 949
previous: null
results […]
next: “https://pokeapi.co/api/v2/pokemon/?limit=20&offset=20

I did a RESTAdapter

RESTAdapter
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
    host:'https://pokeapi.co',
    namespace: 'api/v2',
    
    pathForType() {
      return 'pokemon';
    }
});

and a RESTSerializer

RESTSerializer
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
    primaryKey: 'name', 
    
    normalizeResponse(store, primaryModelClass, payload, id, requestType) {
        payload = {monster: payload.results}
        return this._super(store, primaryModelClass, payload, id, requestType);
    }
});

to catch only the 20 pokemons that are in results. Now I want to learn how to do pagination using a RESTful API with filters made in the backend, I have not found anywhere an example using REST API.

Please help me!!

ps: Sorry for my english