In recent years, most web-based APIs worked in a style called REST. With this approach we would interact with servers to request and send data using d

GraphQL - GetStartedWith.dev

submited by
Style Pass
2021-07-15 11:00:08

In recent years, most web-based APIs worked in a style called REST. With this approach we would interact with servers to request and send data using different URLs that defined the kind of response we wanted.

With REST we would make GET requests for data, PUT or POST requests to send data to the server to make changes. We'd use different URLs for different sets of data.

GraphQL is different. It still allows us to make requests to our API server, but it allows us to more carefully describe the shape of the data we want back. In doing so, we can ask for just the data we need, and reduce the number of requests needed to request complex data sets.

For example, with REST we could send a GET request to a movies API to obtain a list of newly released movies. We would send a GET request to something like oursite.com/api/movies/new and it would give us a list of movie IDs.

If we wanted specific movie details on each of those IDs, we would need to then assemble at least one more query to ask for each of the movies by ID.

Leave a Comment