Is routing method basically arbitrary and just agreed by convention?

In the APIs and Microservices course, we were taught how to use method like GET or POST when dealing with requests. I wonder if we can use GET to update instead of PUT, and GET instead of POST to have something sent to the server (as per my understanding this is the function of POST), because what matters is actually the handler function. If we use the correct handler for our purpose, then the method should not matter, no?

I am sure that is possible. “GET”, “POST”, etc are just for ease of use.

No, it’s not arbitrary at all. Yes, in your application you could make your handler functions do unexpected things that don’t match what is expected for a particular HTTP method, but that would be extremely confusing

No, that’s not really how HTTP (and by extension most of the internet) works. In this case, the relevant Express functions are named to match the relevant HTTP verbs. You can make the handler functions do whatever you want (it’s your application), but making them do something different to what they’d be expected to do would produce extremely confusing programs.

When a client sends an HTTP request to a server, the first line of the request must include the method. The server reads the request and sends a relevant response based on the method.

Last update to HTTP/1 (2014): https://tools.ietf.org/html/rfc7230

The list of valid methods (first characters [ie set of bytes] on the subject line of an HTTP request made by a client): https://tools.ietf.org/html/rfc7231#section-4

2 Likes