SaveMyCert
Cloud basics

REST vs GraphQL: what is the difference?

REST and GraphQL are two approaches to designing web APIs: REST exposes multiple endpoints that each return a fixed shape of data, while GraphQL exposes a single endpoint where the client asks for exactly the fields it needs. GraphQL helps avoid fetching too much or too little data, but it moves complexity to the server and makes HTTP caching trickier. REST is simpler and widely understood, but can need several round trips or return more than a client wants. Neither is better in general. This guide compares them fairly and helps you decide which fits.

How REST works

REST organises an API around resources, each with its own URL, and uses standard HTTP methods such as GET and POST to act on them. A client asking for a user hits one endpoint, and asking for that user’s orders hits another, and each response has a shape the server decided in advance. Its strengths are simplicity, predictability and a natural fit with web infrastructure. Our what is a REST API and what is an API guides cover the basics if these terms are new.

How GraphQL works

GraphQL is a query language for APIs in which clients send a query to a single endpoint describing exactly which fields and related data they want, and the server returns precisely that. A client can fetch a user and their orders in one request and omit fields it does not need. This tackles two familiar REST frustrations: over-fetching, where an endpoint returns more than the client wants, and under-fetching, where several requests are needed to assemble one screen. Our what is GraphQL guide goes deeper.

Side by side

The differences come down to a handful of design trade-offs:

  • Endpoints: REST uses many endpoints, one per resource; GraphQL typically uses a single endpoint.
  • Response shape: REST returns a shape fixed by the server; GraphQL returns what the client asks for.
  • Over- and under-fetching: more common with REST; largely avoided with GraphQL.
  • Caching: REST works naturally with standard HTTP caching; GraphQL caching usually needs extra tooling.
  • Server complexity: REST is simpler to build and reason about; GraphQL needs a schema, resolvers and care with expensive queries.
  • Learning curve: REST is familiar to most developers; GraphQL has more concepts to learn up front.

When to choose which

REST is often the better fit for straightforward resource-based APIs, public APIs that benefit from simple HTTP caching, and teams that want the most familiar approach. GraphQL tends to shine when many different clients, such as web and mobile, need different slices of the same data, or when screens combine data from many related resources and round trips hurt. The honest cost of GraphQL is on the server: you must guard against overly deep or expensive queries and plan caching deliberately.

It also is not all-or-nothing. Many organisations run REST for some services and GraphQL for others, or put GraphQL in front of existing REST services.

In the cloud and in cert study

Cloud providers offer managed services for both styles, such as API gateways for REST-style APIs and managed GraphQL offerings, so the choice is a design decision rather than a platform limit. API design appears in developer and solutions-architecture material; our /revision library covers that syllabus lesson by lesson, and you can check each provider’s documentation for the specifics of its current services.

Ready to start studying — free?

Original practice questions, timed mock exams and revision notes. No card, nothing to pay.

Jump straight into an exam
DVA-C02SAA-C03

Questions, answered

REST exposes multiple endpoints that each return a fixed data shape, while GraphQL uses a single endpoint where the client specifies exactly which fields it wants. GraphQL reduces over- and under-fetching but adds server-side complexity.

Sources

Exam details in this post come from the vendor's published exam guide, which is the authority on what is tested and how.

Keep reading

Cloud basics
Symmetric vs asymmetric encryption: what is the difference?
Cloud basics
TCP vs UDP: what is the difference?
Cloud basics
What is a SIEM? Security information and event management
Cloud basics
What is incident response? The lifecycle explained