01 - Routes intro
In this module, we'll introduce the concept of routes.
Routing Defined
Routing refers to determining how an application responds to a client request to a particular endpoint. An endpoint is a path and a specific HTTP request method attached to that path (GET, POST, DELETE, PUT).
Overview
Here's a rough diagram of what's happening with our recent code that was used as a test in Postman:

Analysis
A GET request is made to localhost:3000/api/test.
When the route is requested, Express finds the method for the specific route. The method that we already added for testing Postman is below:
app.use('/api/test', function(req, res){ res.send("This is data from the /api/test endpoint. It's from the server."); });
So when we go to the
/api/test/
endpoint, we fire off an Express functionres.send
.res
(short forresponse
) handles packaging up the response object.The
.send()
method does the job of sending off the response.
Last updated