Show HN: A CLI to avoid remembering HTTP status codes
github.com
github.com
I use a bash function to load the MDN page for the status:
function man-http() {
code="$1"
if [[ -z $code ]]; then
echo "Usage: man-http <status code>"
exit 0
fi
firefox "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/$code"
} alias status_codes="curl --silent https://developer.mozilla.org/en-US/docs/Web/HTTP/Status | htmlq --text 'dt a code'"
Prints something like this: 100 Continue
101 Switching Protocols
102 Processing
103 Early Hints
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
...
To get specific groups, I do something like this: status_codes | grep ^2
Replacing 2 with whatever group you want, like 4 for 4xx codes for exampleI made a CLI tool (bash) that leverages imgcat (the one that comes with iTerm2) to display images (in my terminal) from http.cat that correspond to the code I'm wondering about as well as a link to the mozilla docs with more details if i need them.
seeing the cats injects a smile into the frustration around "what the heck is a 407?!"
https://github.com/masukomi/masuconfigs/blob/master/bin/http...
>>> from http import HTTPStatus
>>> HTTPStatus.OK
<HTTPStatus.OK: 200>
>>> HTTPStatus(404)
<HTTPStatus.NOT_FOUND: 404>.bashrc:
httpcode () { python3 -c "from http import HTTPStatus; print(HTTPStatus($1))" }
HTTPStatus($1).name.title().replace('_',' ')
Their blog post about reviving the project: https://jkulton.com/2022/reviving-httpstatuses
I've had great success using this sort of know-your-data "smart" search on company-internal databases for customers. People like it because it's intuitive and they don't need to remember keywords or mess with dropdowns.
Also, why don't you just call it http?
man HTTP::Status # courtesy of Perl and HTTP::Status
pydoc requests.status_codes # because Python and requestsP.S. For some reason I can't remember if 301 or 302 is the permanent one.
P.P.S. I hate the fact that 401 should be Unauthenticated (instead of Unauthorized), and 403 should be Unauthorized (instead of Forbidden).
It's definitely not complete, but very helpful to decide which status code makes sense for a particular situation.
lynx -dump https://developer.mozilla.org/en-US/docs/Web/HTTP/Status > HTTP-status-codes.txt
grep 204 HTTP-status-codes.txt
grep 307 HTTP-status-codes.txtNow I just go to http.cat.
Why not simply do this?
$ hssp 204
$ hssp 2 -- lists everything under it
For those that think that `man` is only about commands, we already have `man 7 ascii`.