3. Fetching

3.1 Retrieving a single Pokemon

The one method is used to retrieve a single Pokémon by its ID:

/* GET api/pokemon/1 */
const bulbasaur = await Pokemon.one(1);

Optionally you can add a second parameter to define the query parameters:

/* GET api/pokemon/1?active=true */
const bulbasaur = await Pokemon.one(42, { active: true });

3.2 Searching for one Pokemon

The findOne method is used to retrieve a single Pokémon based on query params:

/* GET api/pokemon?name=bulbasaur */
const bulbasaur = await Pokemon.findOne({ name: 'bulbasaur' });

Use when you want to find entities which do not have an ID, rr when you only want to find a single entity by a custom predicate.

3.3 Retrieving a page of Pokemon

The page method is used to retrieve a Page of Pokémon:

/* GET api/pokemon?page=1 */
const page = await Pokemon.page({ page: 1 });

3.4 Retrieving a list of Pokemon

We recommended using the page method whenever possible as it gives you more flexibility and is more memory efficient.

The list method is used to retrieve a list of Pokémon:

/* GET api/pokemon?limit=10 */
const pokemons = await Pokemon.list({ limit: 10 });

Useful when retrieving a fixed set of data with limited items.

3.5 Page vs List

Prefer page over list when possible because it is more memory efficient to load only a single slice of the data at a time.

It must also be noted that it is very unlikely that a REST endpoint supports both page and list at the same time. So use the variant which your back-end exposes.

Now that we know how to get data, lets see how we can mutate it.