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 REST APIs with Express!
You have completed REST APIs with Express!
Preview
The Express.router() function allows us to put our routes in their own file, as well as add a /api to all the endpoints for our API.
This video doesn't have any notes.
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
For example, if you look at the
documentation for the randomuser API or
0:00
the Star Wars API,
0:02
both expect the client to make a request
to an endpoint beginning with /api.
0:04
We can set up our API the same
way within an express router,
0:09
which is created using a method
called express.router.
0:12
Doing it this way will be
beneficial in two ways.
0:15
We can map each of our routes to
an endpoint that starts with /api,
0:19
without having to repeat /api for
each and every route.
0:23
And it will help keep our
express files more modular.
0:26
We can move all of our routes out
of app.js and into their own file.
0:29
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