top | item 32164667

Show HN: A CLI to avoid remembering HTTP status codes

44 points| sterchelen | 3 years ago |github.com

To understand the meaning of an HTTP status code and list all codes belonging to a specific class from your terminal.

36 comments

order
[+] danstewart_|3 years ago|reply
This looks good.

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"  
  }
[+] tuxie_|3 years ago|reply
From your description I thought for a second that you were somehow parsing the page :D
[+] bil7|3 years ago|reply
i keep underestimating the power of bash. KISS!
[+] masukomi|3 years ago|reply
I took a slightly different approach to this problem.

I 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...

[+] itsmemattchung|3 years ago|reply
I refer to HTTP Status codes all the time throughout the day and use Python's built-in http library:

  >>> from http import HTTPStatus
  >>> HTTPStatus.OK
  <HTTPStatus.OK: 200>
  >>> HTTPStatus(404)
  <HTTPStatus.NOT_FOUND: 404>
[+] rlopezcc|3 years ago|reply
Nice.

.bashrc:

httpcode () { python3 -c "from http import HTTPStatus; print(HTTPStatus($1))" }

[+] dolmen|3 years ago|reply
I was loving httpstatuses.com, but the domain has been recently sold and lost all the clean style that made it useful.
[+] citricsquid|3 years ago|reply
I sold httpstatuses.com (website and domain) in... 2016 I think, maybe 2017, and the acquirers kept it as-is until 2022. Someone (not me) recently relaunched the site (as it was opensource) under a new domain -- https://httpstatuses.io -- so if you can replace ".com" with ".io" in your muscle memory, you can get the original site!

Their blog post about reviving the project: https://jkulton.com/2022/reviving-httpstatuses

[+] muhehe|3 years ago|reply
"There's an app for that" now coming to your terminals...!
[+] the_biot|3 years ago|reply
You can actually just do without the keywords: it's easy to figure out what is intended since class will never reach 100, and code will never go under 100. Will make this more intuitive to use since there's nothing to remember.

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?

[+] darrenf|3 years ago|reply
The CLI ways I already have installed:

    man HTTP::Status            # courtesy of Perl and HTTP::Status
    pydoc requests.status_codes # because Python and requests
[+] b0afc375b5|3 years ago|reply
I've always used this one:

https://www.httpstatuses.org/

P.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).

[+] rlupi|3 years ago|reply
Nice work gathering all HTTP codes, but wouldn't this be simpler?

  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.txt
[+] robofanatic|3 years ago|reply
I guess you can make the usage bit simpler by getting rid of "code" and "class" keywords

Why not simply do this?

$ hssp 204

$ hssp 2 -- lists everything under it

[+] spl0i7|3 years ago|reply
I'd prefer a man page than having to install separate tool :)
[+] dolmen|3 years ago|reply
`man 404` would be really convenient. I could tolerate `man http-404` too.

For those that think that `man` is only about commands, we already have `man 7 ascii`.

[+] cowbolt|3 years ago|reply
FYI: Successful is written without two L's. Looks like a useful tool though :)
[+] bmn__|3 years ago|reply

[deleted]

[+] thefreeman|3 years ago|reply
This comment is completely unnecessary and adds nothing to the discussion. How is the author publishing source code on his own github repo "burdening the public".
[+] hk1337|3 years ago|reply
I would have used the Mozilla docs as a more official reference.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

You want to bring up pollution, what about the plethora of http status reference sites we already have. At least OP kept it to CLI. It’d be nice if it sourced it from Mozilla so it wouldn’t need updating.

[+] CoffeeCollector|3 years ago|reply
Completely agree. The pollution metaphor is apt: Not only the cognitive cost of looking over this code, realizing it’s displaying a CSV, and offering advice but also the real CO2 cost of hosting, packaging, distributing, running, and maintaining this code. Truly progressive devs should always consider these costs.