Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
What is a REST API, and why might you want to use one?
To be successful in this course, you’ll need to be familiar with the basics of building a server side Express application. Check out the Express Basics course.
If you’re unfamiliar with how call callbacks, promises and async/await are used in Express, check out the Asynchronous Code in Express course
Asynchronous JavaScript Resources:
[MUSIC]
0:00
>> Hey, I'm Treasure, a JavaScript
developer and teacher here at Treehouse.
0:08
In this course, we'll be using
the popular Node.js platform and
0:12
Express framework to build a type of
web application called a REST API.
0:16
To define a REST API, we first need to
talk about a traditional web application.
0:21
Traditional web applications handle
both serverside and clientside concerns.
0:25
Say you build a web application to keep
a record of your favorite recipes.
0:30
To view a certain recipe,
you'd click on that recipe's URL, and
0:34
your browser would request
that recipe from a server.
0:37
A traditional server side application
would respond to that request by finding
0:40
the RESP data in a database, assembling
that data into HTML templates and
0:45
sending that HTML back to
the browser to be displayed.
0:50
Seems reasonable but what if you wanted to
use that same RESP information to build
0:53
a mobile app or
an entirely different application?
0:57
That's where REST API comes in, when you
request a specific recipe in a RESTful
1:01
application, the application
responds only with the recipe data,
1:05
typically in the form of JSON.
1:09
Sending JSON data rather than HTML means
the back end only has to be built once.
1:11
While any number of front end applications
can consume and display the data.
1:16
When designing an application this way,
1:20
you can manipulate the same
data in endless ways.
1:22
If I have a REST API for recipes, for
example, I could create a recipe website.
1:25
But I could also use the same data
to create a meal planning app,
1:30
a calorie tracking app,
a virtual cookbook, and on, and on.
1:33
As another good example,
think about the Twitter app on your phone.
1:37
The phone app makes a request
to Twitter RESP API,
1:40
to get the tweets before you see them.
1:43
The JSON from Twitter's API is then
formatted and displayed on your phone.
1:46
But the Twitter API allows the same
tweet data to be accessed and
1:50
used by a web browser,
a smart TV, or a home IoT device.
1:54
REST APIs can provide data and content for
rich web applications, mobile apps,
1:57
and other serverside applications,
2:02
even those applications written
in other programming languages.
2:04
Basically, a REST API lets
you retrieve data and
2:08
present that data in any way you want,
providing amazing flexibility.
2:11
I'll review some key concepts in
this course, but to be successful,
2:15
you should be familiar
with the basics of node,
2:19
building a serverside application
with Express, and Express middleware.
2:22
You should also be familiar
with asynchronous JavaScript,
2:26
specifically using Callbacks,
Promises, and Async Await.
2:29
See the teacher's notes below for
the prerequisite courses.
2:32
In this course, we'll use Node and
2:36
Express to build out a simple API that
provides data about famous quotes.
2:38
When we're finished, users will be able
to request famous quotes from our API,
2:43
as well as add new quotes, edit and
delete existing quotes, and
2:47
request a random quote.
2:50
As we build this project,
you'll learn more about how API's work and
2:52
specifically, how to
build one with Express.
2:56
Let's dig a bit more into
the structure of an API.
2:59
You need to sign up for Treehouse in order to download course files.
Sign up