Adding routes
To specify how the application responds to client requests, routes must be defined. Each route is identified mainly by an HTTP method and a URL pattern, which must align with the incoming request to execute the associated handler function. We are currently exposing only one single route: GET /
. If you try to hit a different endpoint, you will receive a 404 Not
Found
response:
$ curl http://localhost:3000/example {"message":"Route GET:/example not found","error":"Not Found","statusCode":404}
Fastify automatically handles 404 responses. When a client attempts to access a non-existent route, Fastify will generate and send a 404 response by default.
As we’re developing a web server to provide APIs for our fantasy restaurant, it’s essential to outline the routes we need to implement in order to fulfill our objectives. Some of the necessary routes may include the following:
GET /menu
: Retrieves...