Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to GraphQL!
You have completed Introduction to GraphQL!
Preview
How does GraphQL differ from REST services? In this video, we will go over some simple example REST APIs, and what they would look like expressed with GraphQL.
New Terms:
- REST - A RESTful API is one that uses HTTP requests to GET, PUT, POST, and DELETE data. For example: http://api.example.com/movies/gone-with-the-wind
Further Reading:
GraphQL vs. REST by Sashko Stubailo
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
If you've built a modern web application,
0:00
chances are you've used
a REST API at some point.
0:03
REST has been the gold standard for
0:06
API development since as far back
as 2000 when Roy Fielding published
0:08
his paper that demonstrated a more
intuitive way of organizing APIs.
0:12
While REST has served the web
community well, in the past 15 years,
0:18
we've also learned some of
the challenges that come with it.
0:22
Let's take, for example, a simple
Hollywood API which exposes data about
0:25
various movies and
the studios involved in producing them.
0:30
Say we wanted to fetch some
information about a specific movie
0:35
from the Hollywood API using REST.
0:38
We'd probably hit an endpoints
that looks something like this.
0:41
We'd use an HTTP get method
with a base path of movies,
0:44
followed by a parameter containing the
movie ID, for example, Gone with the Wind.
0:49
The API would respond by
returning a movie object,
0:55
which would contain simple
fields that describe the movie.
0:58
Like an ID, a title, and a tagline.
1:01
Say we only needed the title
of a specific movie.
1:05
Best case scenario,
1:07
we'd have to add an unintuitive query
string to the end of our request URL.
1:09
Or even more likely, we wouldn't be
able to make this change at all.
1:14
For more complex objects,
1:18
it would probably feature fields that
contain references to other objects.
1:20
For example, it might have a studio field.
1:24
But the studio field wouldn't
contain the actual studio object.
1:27
Instead, it would have an ID that could
be used with the studio's end point.
1:32
In order to get information
about the studio,
1:37
we would need to make another
request with the studio ID.
1:40
That end point would return more
simple fields like the studio name and
1:44
location and maybe the IDs of movies
that the studio had produced.
1:48
Now, let's use the same example to
see how Graft QL differs from REST.
1:54
With Graft QL we would have a root level
end point for movies called movieById.
2:00
However, unlike REST,
2:06
when querying that endpoint we can include
as many or as few fields as we need.
2:07
Not only that, but when querying for
a movie, we could actually request that
2:13
GraphQL embed the details about
its studio in the same response.
2:18
So we only have to make one request
to learn more about both items.
2:23
We'll dive into more about
this later in the course.
2:28
For now, just note that GraphQL allows us
to nest complex data in a single request.
2:31
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up