01 - Routes intro
Last updated
Last updated
In this module, we'll introduce the concept of routes.
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).
Here's a rough diagram of what's happening with our recent code that was used as a test in Postman:
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:
So when we go to the /api/test/
endpoint, we fire off an Express function res.send
.
res
(short for response
) handles packaging up the response object.
The .send()
method does the job of sending off the response.