Open dbrgn opened 4 years ago
Shall we do the same for DELETE, PATCH, etc. usw. i mean it is "more right" but i usually haven't seen it in the wild.
We could, but for those it's much less relevant. I often "explore" RESTful APIs by simply GETing an URL. If it returns 404, I'd assume that the resource doesn't exist. If it returns 405, I know that I'm using the wrong method.
Usually these things are handled even by the most simple web frameworks. You register a POST handler for a URL, then it knows that other methods should return 405, and will also generate a proper OPTIONS response. Of course the API works without that, but I'd not consider it RESTful. (It doesn't need to be, but I find RESTful APIs very useful.)
Aren't there commonly used libraries that offer this for Go?
We could, but for those it's much less relevant. I often "explore" RESTful APIs by simply GETing an URL. If it returns 404, I'd assume that the resource doesn't exist. If it returns 405, I know that I'm using the wrong method.
Usually these things are handled even by the most simple web frameworks. You register a POST handler for a URL, then it knows that other methods should return 405, and will also generate a proper OPTIONS response. Of course the API works without that, but I'd not consider it RESTful. (It doesn't need to be, but I find RESTful APIs very useful.)
Aren't there commonly used libraries that offer this for Go?
There are, but this one is very very lightweight and small. I wanted to start with it since it does. The 405 behavior would be easy to implement too, but maybe we need something bigger.
In Python I usually use something like Bottle or Flask, which are very small and don't get in your way :slightly_smiling_face: (Bottle is just this file, a bit more than 4000 LOC including comments and empty lines.) I'm not familiar with the golang micro-webframework landscape though.
In Python I usually use something like Bottle or Flask, which are very small and don't get in your way slightly_smiling_face (Bottle is just this file, a bit more than 4000 LOC including comments and empty lines.) I'm not familiar with the golang micro-webframework landscape though.
goji is about a thousand including all type definitions. Its using the basic golang functions and focusing on composition and keeping the api stable.
But anyways, that's not what i would like to focus on, i would like to focus on making it easily accessible. For instance i would like to redirect the root to something like swagger ui and make it easy to generate clients instead of letting people run around in the api itself (but of course doing it RESTful).
I don't mind generated clients, although I don't use them myself. But the API is a contract, it should always be well-defined and behave according to the REST principles :slightly_smiling_face: Using custom helpers for things like OPTIONS is fine for me, although that's something I usually delegate to a microframework.
A GET Request to /v1/validate returns 404 Not Found, but it should return 405 Method Not Allowed.