REST vs GraphQL
A REST API gives every thing its own address and uses HTTP methods on it. GraphQL sends every query to one address and lets the client pick the exact fields. REST is simpler to cache; GraphQL saves trips on a slow phone.
REST API
A web API where each thing has its own address, and HTTP methods act on it.
A REST API gives each thing, called a resource, its own web address. You act on them with the normal HTTP methods: GET to read, POST to create, PUT or PATCH to change and DELETE to remove. Each request carries everything the server needs, so the server keeps no memory between requests. Answers are usually JSON. REST was described by Roy Fielding in 2000 and is the most common style of web API.
GraphQL
A way to ask an API for just the fields you want, in one go.
GraphQL is a query language that lets a client ask for exactly the fields it wants. All requests go to one address, and each one says the shape of the answer it expects. One request can gather data that a REST API would spread across several calls. The server publishes a schema that lists every type and field you can ask for. Facebook built it and released it to the public in 2015.
In one line
- REST API
- A web API where each thing has its own address, and HTTP methods act on it.
- GraphQL
- A way to ask an API for just the fields you want, in one go.