Q2: How does GraphQL differ from a traditional REST API?
In REST, endpoints represent resources (e.g., /users, /posts), and data structure is fixed by the server. GraphQL uses a single endpoint (typically /graphql) where clients post a structured query specifying the exact response shape.
REST vs GraphQL Comparison
Endpoints:
Multiple resource URIsREST requires multiple network calls for relational data.
GraphQL Endpoints:
Single endpointGraphQL executes complex declarative queries at one endpoint.
Data Fetching:
Server defines payloadREST payload structure is static.
GraphQL Data Fetching:
Client defines payloadGraphQL response reflects requested schema fields.
Key Takeaways
- REST relies on multiple resource endpoints, while GraphQL operates over a single endpoint.
- GraphQL gives the client total control over response shape.
Knowledge Check
What is the typical network architecture for a standard GraphQL server?