SyntaxStudy
Sign Up
GraphQL GraphQL vs REST: Key Differences
GraphQL Beginner 1 min read

GraphQL vs REST: Key Differences

REST APIs model resources as URLs (e.g. /users, /posts), while GraphQL models the API as a typed graph of connected objects. REST relies on HTTP verbs to signal intent; GraphQL uses three operation types—query, mutation, and subscription—all sent over HTTP POST (or GET for queries). Versioning is another key difference. REST APIs frequently ship v2, v3 endpoints to avoid breaking changes. GraphQL APIs are designed to be evolved by adding new fields and deprecating old ones, keeping a single schema that backward-compatible clients continue to use without modification.
Example
# ----- REST vs GraphQL comparison -----

# REST: multiple endpoints, fixed shapes
# GET  /users/42          -> full user object always returned
# GET  /users/42/posts    -> separate request
# POST /users             -> create user
# PUT  /users/42          -> update user

# GraphQL: one endpoint, flexible shapes
# POST /graphql  with body:

# 1. Query (read)
query {
  user(id: "42") {
    name          # only these two fields
    email
  }
}

# 2. Mutation (write)
mutation CreateUser($input: CreateUserInput!) {
  createUser(input: $input) {
    id
    name
  }
}

# 3. Subscription (real-time)
subscription OnNewPost {
  postCreated {
    id
    title
    author { name }
  }
}

# GraphQL never breaks old clients — just add fields, deprecate old ones:
# type User {
#   name: String
#   fullName: String @deprecated(reason: "Use `name`")
# }