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