Course contentsShow
← Web Development
Lesson 1546 of 2,98228. GraphQL FundamentalsFree lesson

REST's Resource-Centric Model vs GraphQL's Query-Centric Model

Understanding how REST organizes data around resources and endpoints versus GraphQL's single endpoint with flexible queries.

REST's Resource-Centric Model vs GraphQL's Query-Centric Model

What you'll learn: How REST and GraphQL take fundamentally different approaches to organizing and accessing data through their APIs.

The Fundamental Difference

REST and GraphQL represent two distinct philosophies for API design. REST organizes everything around resources—nouns that represent entities in your system (users, posts, comments). Each resource gets its own URL endpoint, and you use HTTP methods to interact with it. GraphQL, on the other hand, centers around queries—asking for exactly what you need through a single, flexible endpoint.

REST: The Resource Organization

In REST, you navigate a map of resources. Want user data? Hit /users/123. Need their posts? Visit /users/123/posts. Each resource is a destination with its own address. This is like having separate stores for groceries, hardware, and clothing—you visit each location for specific items.

The structure is predictable but rigid. If you need user info AND their posts AND comments, you're making multiple trips to different endpoints or creating custom endpoints like /users/123/profile-with-posts.

GraphQL: The Query Flexibility

GraphQL flips this model. There's typically one endpoint (often /graphql), and you describe exactly what data you want in your query. It's like having a personal shopper: you hand them a detailed list, and they gather everything in one trip.

Instead of endpoint proliferation, you write precise queries that traverse relationships on-demand. Need a user with their posts and each post's comments? Write one query that specifies that exact shape of data.

The Trade-offs

REST's resource-centric approach is intuitive and cacheable but can lead to over-fetching or under-fetching. GraphQL's query-centric model gives clients precise control but shifts complexity to query design and server-side resolvers.

Key Takeaway: REST organizes APIs around resources with multiple endpoints and fixed responses, while GraphQL uses a single endpoint where clients specify exactly what data they need through flexible queries.