PureTools

GraphQL vs REST: When Each One Wins

PureTools Team· 7 min read
GraphQL vs REST: When Each One Wins

GraphQL vs REST: The Honest Trade-offs

GraphQL isn't better than REST. REST isn't better than GraphQL. Each has trade-offs that make it better for specific situations.

Quick Comparison

FeatureRESTGraphQL
EndpointsOne per resource (/users, /posts)Single endpoint (/graphql)
Data fetchingServer decides shapeClient decides shape
OverfetchingCommon (get entire object)Solved (request only needed fields)
UnderfetchingCommon (multiple requests)Solved (nested queries)
CachingHTTP caching (built-in)Requires client-side caching (Apollo)
File uploadsNative (multipart)Awkward (spec extension needed)
Learning curveLowMedium-High
Toolingcurl, Postman, any HTTP clientApollo, Relay, GraphiQL

REST Example

// Get user profile + their posts + each post's comments
// Requires 3+ requests:
GET /users/42                    // user data
GET /users/42/posts              // user's posts
GET /posts/101/comments          // comments for post 101
GET /posts/102/comments          // comments for post 102
// N+1 problem: 1 + 1 + N requests

GraphQL Example

// Same data, one request:
query {
  user(id: 42) {
    name
    email
    posts {
      title
      publishedAt
      comments {
        text
        author { name }
      }
    }
  }
}

When to Choose REST

  • Simple CRUD apps
  • Public APIs (easier to document, cache, rate-limit)
  • File upload/download heavy services
  • Team is familiar with REST, deadline is tight
  • Microservices communicating with each other
  • When HTTP caching is critical

When to Choose GraphQL

  • Complex UIs with many related data types
  • Mobile apps (bandwidth matters, fetch only what you need)
  • Multiple client types (web, mobile, TV) with different data needs
  • Rapid frontend iteration (don't wait for backend to add endpoints)
  • When you'd otherwise build 20+ REST endpoints

GraphQL Gotchas

  • N+1 queries on the server: Use DataLoader to batch database queries
  • No HTTP caching: All requests are POST to /graphql — CDN caching doesn't work out of the box
  • Security: Malicious queries can be deeply nested. Use query depth limiting and complexity analysis
  • File uploads: Not part of the spec. Use multipart upload extensions or separate REST endpoints

The Middle Ground

Many teams use both: REST for simple CRUD and public APIs, GraphQL for complex frontend data requirements. They're not mutually exclusive.

Format your queries: JSON Formatter — format GraphQL responses for debugging.