This course will be retired on August 10, 2021. We recommend "REST APIs with Express" for up-to-date content.
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
Now that we have a general sense of how our service will respond to requests, let’s figure out exactly what routes (URL’s), into our service we want to provide.
Now that we have some solid concepts
of what we're going to implement,
0:00
let's begin building the interface.
0:03
I'm not talking about
the visual user interface.
0:05
I'm talking about the I in API or
application programming interface.
0:08
In other words, we need to describe
how the program talks with or
0:13
interfaces with the service
we're building.
0:17
The interface to our API
is made up of URL patterns.
0:20
Each URL pattern is known as a route.
0:24
Planning routes is an important step.
0:27
You don't want to make any
changes once you launch your API,
0:29
as this would break applications that
would rely on the data from API.
0:33
Let's look at an example URL,
example.com/about/index.html.
0:37
This URL is the route to
the index.html file in the about
0:45
folder located at the example.com domain.
0:50
This is why we call our URLs routes.
0:54
They route us to a specific
resource location.
0:58
API routes follow the same
logical structure
1:01
where the slashes describe
the nested resources.
1:04
Resources to the left of each slash
own the resources to the right.
1:07
If we start with our APIs
most general root resource,
1:13
we can naturally build towards
the dependent resources as we go.
1:16
Because we can't answer a question that
doesn't exist yet, it makes sense for
1:20
our route resource to be a question.
1:24
Our best route is slash questions.
1:28
Notice it's questions plural and
not question singular.
1:31
This indicates that
the route provides access to
1:35
all the questions in our database.
1:38
This is a GET route which
lets us read questions.
1:41
We need to post to the route
/questions to create a question.
1:45
To read a specific question we can have
the URL pattern of /questions/:id.
1:49
We can access a specific
question by its ID.
1:55
This is a get request to this route and
should return a single question.
1:59
We are going to be
implementing the editing or
2:03
the deleting of questions in our API.
2:06
If you wanted to do either of those
things you'd have to go into the database
2:08
manually and perform those actions.
2:12
Now that our question routes are complete
let's build the answer routes next.
2:15
You need to sign up for Treehouse in order to download course files.
Sign up