Understanding routing
An essential part of the design of a REST API is the routing. This involves defining how you will structure the URLs and HTTP methods that your API responds to. For example, you can have the /api/v1/users resource, the /api/v1/films resource, and so on. But you can decide to follow a more nested approach. For example, you can have /api/v1/users/1/films. It’s up to you to decide how you want to structure your API, but consistency is important. I like the flat approach, but in my opinion, there’s nothing wrong with the nested approach.
For routing in Go, we will use the standard library’s http package in this book; however, there are other libraries you can use, such as gorilla/mux, gin, chi, and others.
Let’s say that I want to define my users’ resource in the /api/v1/users path using the standard library router (this routing is only available since Go 1.22). I would do something like this:
http.HandleFunc("GET...