API Fundamentals Course
API Fundamentals
/
Intermediate

GraphQL vs REST

Definition

Comparing the two dominant Web API architectures. REST relies on multiple endpoints returning fixed data structures. GraphQL relies on a single endpoint returning dynamic, client-defined data structures.

Explain Like I'm New

REST is a set menu at a restaurant. You order the 'Burger Meal' (Endpoint), and you get a burger, fries, and a drink, whether you want them or not. GraphQL is a buffet. You walk up to one counter (Single Endpoint) and put exactly 3 fries and half a burger on your plate.

Real World Example

To show a blog dashboard, a REST app makes 3 requests: `/user`, `/posts`, and `/followers`. A GraphQL app makes 1 request to `/graphql` asking for the user, their posts, and their followers all at once.

Common Use Cases

  • •Architecture decisions

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • How many Endpoints (URLs) does a standard GraphQL API usually expose?

intermediate

  • Why is HTTP Caching inherently harder in GraphQL compared to REST?

Flash Cards

Question

How many endpoints?

Click to reveal answer
Answer

Usually just ONE (e.g., `POST /graphql`). All queries and mutations are sent to this single URL.

Question

Why is caching harder?

Click to reveal answer
Answer

REST relies on unique URLs. Browsers and CDNs know how to easily cache `GET /users/5`. Because GraphQL sends almost every request as a `POST` to the exact same `/graphql` URL with a complex body, standard network caching breaks down. You have to use complex client-side caching libraries like Apollo.