Just one thing I stumbled across that wasn't immediately obvious.
The Echo library for Go is a lightweight framework for building web apps with an HTTP server. I like it, it's fun.
One of the features is "binding", that is, binding user input to variables, for example, from JSON input or other means like query parameters. It comes with a handy catch-all function:
body := struct{
id int
data string
}{}
c.Bind(&body)
Now THAT is convenient. Even more convenient is that it will bind it from anything: - Query parameters - Unmarshalled data - Path params - Headers
Just think of all of the flexibility that you will get for FREE!
Now, before you give the green light for a mega flexible API, consider what else you're doing:
- Exposing more methods
A proper test suite tests all methods of input. There might be hidden limitations or nuanced behavior when specifying input with certain methods. All of that should have tests.
Additionally, when you decide later down the line that you don't really like Echo's binding methods, you can't remove that flexiblity, lest you commit API taboo by removing methods that are already exposed.
You can always add functionality later, so exercise a bit of restriction with Echo's specific binding methods:
func bindBody(c echo.Context, body any) error {
return (&echo.DefaultBinder{}).BindBody(c, body)
}