When creating method routes, do we need to keep an order?

Question

When creating method routes, do we need to keep an order?

Answer

There is a certain specificity on how we arrange our routes based on the route and then on the method. We want to keep the order in which requests can come in, that is:

1st: the root route /

This is most commonly only a GET request to the server in general, if we talk about a web app that has a server on its own like Facebook for example, the root route request will fetch all necessary static pages and data to give us the login or home page (depending on what the browser has already stored).

2nd: specific routes, ie: /expressions/ and /animals/

These are the routes that will directly relate to content in bulk, getting all the animals or expressions and creating a new animal or expression. it is important that for each one of these routes you will follow it by its longer paths, for example, setting up:

GET /expressions/
POST /expressions/
GET /expressions/:id
PUT /expressions/:id
DELETE /expressions/:id

and after, having the following specific route:

GET /animals/

which leads us to

3rd: longer routes, ie.: /expressions/:id

this mainly comprises of three functions, Read one object (GET by id), Update (PUT) or Delete (as we guessed DELETE).

That said, there is no greater reason to this than structure since express matches route and method, but it makes it more legible and easier to debug if we ever encounter any issues.

7 Likes