PokeAPI / pokedex-promise-v2

An easy way to use pokeapi v2 with promises in node.js
MIT License
516 stars 91 forks source link

[Question] Array encapsulation functionality #62

Closed EchedelleLR closed 2 years ago

EchedelleLR commented 2 years ago

In the middle of the process of making a Pokédex-like application, I saw that this library provides some kind of array encapsulation, allowing to make several requests with just one function call.

P.getBerryByName(['cheri', 'chesto', 5])
    .then((response) => {
      console.log(response);
    })

However, I want to know how the process is made in order to know if this would transform several requests to the API in just one concatenated.

The idea was to use this to implement a search component in the application since the other way consist in making one request to the general endpoint and a singler request per element of the results in the first request. As result, this could lead a decrement of the requests made to the API.

Naramsim commented 2 years ago

Hi, this works by firing multiple requests.

If you only want to fire a single request and fetch different kinds of data, have a look at GraphQL. https://pokeapi.co/docs/graphql

EchedelleLR commented 2 years ago

Will this implemented through the promises library for fair use and make it easier?

I have no experience in GraphQL nor it is something done at the course level, only RESTful APIs.

Naramsim commented 2 years ago

We have plans to make GraphQL queries easier to write, but we lack time. There's no wrapper supporting GraphQL queries right now but it's as simple as making an HTTP call passing a JSON object. The server rate-limits 100 calls per hour per user/browser

Naramsim commented 2 years ago

Here a Node.js example: https://github.com/PokeAPI/pokeapi/tree/master/graphql/examples/node

EchedelleLR commented 2 years ago

Thank you for all of this.