Learning Library

← Back to Library

REST vs GraphQL: Talkative vs Reserved

Key Points

  • The speaker uses an analogy of two coworkers—talkative “R” (REST) and concise “G” (GraphQL)—to illustrate that REST returns all data by default while GraphQL lets clients request exactly what they need.
  • Both REST and GraphQL are approaches to building APIs, which enable different applications (like web or mobile clients) to communicate with servers over the internet.
  • In GraphQL, a **schema** defines the full data model, **queries** fetch data matching that schema, **resolvers** retrieve and assemble the requested data (potentially from multiple sources), and **mutations** handle create, update, and delete operations.
  • REST is an architectural style centered on **resources**, each identified by a unique URI, and uses standard HTTP methods (GET, POST, PUT, DELETE) to perform CRUD actions on those resources.
  • The key trade‑off is that REST may deliver excess data requiring client‑side filtering, whereas GraphQL offers precise, single‑request data retrieval, reducing over‑fetching and under‑fetching.

Full Transcript

# REST vs GraphQL: Talkative vs Reserved **Source:** [https://www.youtube.com/watch?v=PTfZcN20fro](https://www.youtube.com/watch?v=PTfZcN20fro) **Duration:** 00:07:26 ## Summary - The speaker uses an analogy of two coworkers—talkative “R” (REST) and concise “G” (GraphQL)—to illustrate that REST returns all data by default while GraphQL lets clients request exactly what they need. - Both REST and GraphQL are approaches to building APIs, which enable different applications (like web or mobile clients) to communicate with servers over the internet. - In GraphQL, a **schema** defines the full data model, **queries** fetch data matching that schema, **resolvers** retrieve and assemble the requested data (potentially from multiple sources), and **mutations** handle create, update, and delete operations. - REST is an architectural style centered on **resources**, each identified by a unique URI, and uses standard HTTP methods (GET, POST, PUT, DELETE) to perform CRUD actions on those resources. - The key trade‑off is that REST may deliver excess data requiring client‑side filtering, whereas GraphQL offers precise, single‑request data retrieval, reducing over‑fetching and under‑fetching. ## Sections - [00:00:00](https://www.youtube.com/watch?v=PTfZcN20fro&t=0s) **Untitled Section** - - [00:03:12](https://www.youtube.com/watch?v=PTfZcN20fro&t=192s) **REST vs GraphQL Overview** - The passage explains REST’s core concepts—URI‑identified resources accessed via HTTP methods and returned as JSON or XML—then compares REST to GraphQL, noting that both build APIs over HTTP using JSON but differ in that REST uses multiple resource endpoints with full responses, whereas GraphQL employs a single endpoint allowing clients to request precisely the data they need. - [00:07:16](https://www.youtube.com/watch?v=PTfZcN20fro&t=436s) **Encouraging Viewer Interaction** - The speaker invites viewers to ask questions, like the video, subscribe for future content, and thanks them for watching. ## Full Transcript
0:00So I have these two colleagues. Let's 0:02call them R. 0:04And then we'll call the other one G. 0:08Just using initials here to to protect 0:10their identities. Now R is rather 0:12talkative. They tell you everything they 0:15know whether you want to hear it or not. 0:17G on the other hand is much more 0:19reserved. They share the information 0:21that's absolutely necessary but no more. 0:24But they're always willing to share more 0:26if I do ask. And look, this is one way 0:28that we can think of the differences 0:30between REST, that's the R, and GraphQL, 0:39that's the G. Rest can be a bit of a 0:43know-it-all. You have to be specific in 0:46your requests and sift through all the 0:48data that's returned. With GraphQL, you 0:50can be precise and only retrieve the 0:52data you need. It said that GraphQL 0:55prioritizes giving clients exactly the 0:58data they request and no more. But I'm 1:01I'm getting ahead of myself here. What 1:03clients? What are what are these 1:05technologies do? Well, both REST and 1:08GraphQL are used to build something 1:11called APIs 1:14or application programming interfaces. 1:18And those allow different applications 1:21to communicate with each other over the 1:23internet. So an API takes requests from 1:25a from a client over here and that 1:28client can be like a web application or 1:30a mobile app or something like that and 1:32then it retrieves the necessary data 1:35from a server over here. Now REST or 1:39representational state transfer and 1:42graph query language are two different 1:45approaches to building APIs that have 1:48their own strengths and weaknesses. So, 1:50REST is an architectural style that 1:52relies on HTTP requests to interact with 1:55resources while GraphQL is a query 1:57language that allows clients to retrieve 1:58data from multiple data sources in a 2:01single API call. So, let's define some 2:04terminology and we're going to start 2:07with GraphQL. 2:10So in GraphQL we have something called 2:14a schema and this is the blueprint that 2:16defines all the possible data that 2:18clients can query through a service. Did 2:20I say query? Yeah, query. That's the 2:22next one. So a query is a request for 2:27data that follows the structure defined 2:29in the schema. Then we have something 2:32called a resolver. 2:35And the resolver is called to retrieve 2:38the data that was requested in the 2:40query. And this may involve fetching 2:42data from multiple data sources and 2:44assembling it into a response that 2:46matches the query structure. And then 2:48lastly, we have mutations. 2:51And mutations 2:54their job is to modify data on the 2:56server. So if we think of this in in 2:58terms of the create, read, update, and 3:00delete or the CRUD model, a query that 3:02would be equivalent to the read in a 3:04CRUD. And then all the others, the 3:05create, the update, and the delete, 3:07they're handled by mutations. 3:10So that's GraphQL. 3:12If we take a look at REST, we consider 3:17resources in REST. So resources are 3:20really the fundamental concept in RESTs. 3:23Each resource has a unique identifier 3:25called a URI 3:28that identifies it. So uniform resource 3:30identifier and a client can request a 3:33response using an HTTP method. So the 3:37methods that we can use are get, put, 3:41post and delete. And that gets us access 3:44to those resources. And then the server 3:47responds with a representation of the 3:49resource in a format like JSON or XML. 3:52Now, REST auto allows clients to filter, 3:54sort, and pageionate the data using 3:56query parameters. So, how are GraphQL 4:00and REST similar? Well, both are used 4:04to, as I've mentioned, build APIs that 4:07allow different applications to 4:09communicate with each other over the 4:10internet. both also have a commonality 4:13in that they use frameworks and 4:16libraries 4:17to handle all of the pesky network 4:20details so we don't have to worry about 4:22them and then also both operate over 4:24HTTP although it is worth pointing out 4:26that GraphQL is protocol agnostic also 4:29both can handle requests and responses 4:31using JSON or the JavaScript object 4:35notation 4:36but there are several key differences 4:39between the two technologies that make 4:41them better suited for different use 4:43cases. When requesting data from a 4:46specific endpoint, a REST API returns 4:50the full data set for that resource. 4:51Whereas, in contrast, GraphQL is a query 4:54language specification and set of tools 4:56that allow clients to interact with a 4:58single endpoint. REST APIs often require 5:01multiple requests to fetch related data, 5:04while GraphQL can fetch all the data in 5:06a single request using a complex query 5:09that follows the schema. So clients get 5:12what they request with no overfetching. 5:15Now, REST APIs are already very familiar 5:17to many developers, so people know how 5:19to use them. GraphQL may represent a bit 5:22of a learning curve for some. Rest APIs 5:25are well suited for applications that 5:27require simple CRUD like operations. So 5:32for example, an e-commerce website might 5:34use a REST API to allow customers to 5:36browse products, add items to their 5:39cart, and complete orders. In that case, 5:41the API would use the HTTP methods we 5:43talked about, get put, post, and delete 5:46to manipulate the data like the 5:48products, the orders, and the customer 5:50information. Now on the other hand, 5:52GraphQL is better suited for 5:54applications that require well a bit 5:56more complex 6:00data requests. 6:03And what I mean by that is where we have 6:05examples of many sort of nested fields 6:07or multiple data sources that we need to 6:09pull from. So if we think about a 6:11company that provides a suite of 6:13financial planning tools for its 6:14clients, those tools might require data 6:16from multiple sources. So they might 6:17need to go to bank transactions, 6:19investment portfolios, and credit 6:21scores. And with GraphQL, the company 6:24can build a single API endpoint that 6:26allows clients to query all of the data 6:28in a single request. So clients simply 6:30specify exactly the data that they need 6:32and the server would use a set of 6:34resolvers to fetch the necessary data 6:37from each source and assemble it into a 6:39response that matches the query 6:41structure. Now, REST and GraphQL can 6:44also work together because GraphQL 6:46doesn't dictate a specific application 6:48architecture. It can be introduced on 6:50top of an existing REST API and can work 6:53with existing API management tools. So, 6:56like my work buddies R and G, both REST 7:01and GraphQL have their unique quirks and 7:04strengths. Both have their place in the 7:06world of APIs. And by understanding 7:08their similarities and differences, you 7:10can choose the right tool for the job. 7:14If you have any questions, please drop 7:16us a line below. And if you want to see 7:18more videos like this in the future, 7:20please like and subscribe. Thanks for 7:23watching.