I am working on a project where I have to deal with some HTTP status codes (300, 400, 500, etc).
It is not a project where we use Phoenix and such is even out of the question ( the project is not a good fit for the framework ).
Problem
In my day to day I find my self having to remember what all those codes mean. Eventually I either forget or make a type, send a 403 instead of a 404, for example.
What am I looking for?
Node has a nice little package called HTTPStatus that helps me with this. With it I can type NOT_FOUND instead of 404 and so on.
I was wondering if Hex has something similar, since I didn’t really find anything.
I get the value proposition. The good thing with a library containing HTTP status codes (as functions returning constants?) is IDE autocompletion for example. But the downside is needing to coordinate with HTTP libraries that they understand these constants. They could be straight integers (def not_found(), do: 404) but some libraries prefer atoms instead, so you’d need to ensure they all agree on the atom naming.
I believe you can, I don’t see why not. I think @Nicd meant that it’s not a small library that contains just these codes, and you probably don’t want to add plug to your project just for that function if you’re not already using plug.
That said, if you’re already using plug and this API suits you, feel free to use it. Otherwise you can copy the code to your own module or hand-roll something similar and publish your library on hex
I did have a library called http_status. In the end I moved it into Raxx because it wasn’t adding enough on it’s own. There are quite a few discussions around non standard responses such as 422 that people often need to tweak the library to their own usecase