http.cat icon indicating copy to clipboard operation
http.cat copied to clipboard

suggestion: json response

Open donpdonp opened this issue 4 years ago • 6 comments

it'd be useful to request https://http.cat/401 with either "Accept: application/json" or /401.json to get a response similar to

{ 
 "code": 401
 "description": "Unauthorized"
}

mostly I am looking for a data source for an irc bot to respond to "!http 401".

donpdonp avatar Jan 29 '20 18:01 donpdonp

Hi @donpdonp ,

Thanks for the suggestion. That would definitely be a nice to have. I'll take it into consideration 👍

rogeriopvl avatar Mar 21 '20 18:03 rogeriopvl

I would love to work on this feature, but I am having trouble understanding the current setup. Using the start script, the separate pages are not being displayed and it defaults to root. I assume that they are created in the production build with the react-snap command. However, the post-render script deletes all those created pages for some reason I do not really understand, which means there are still no separate status pages. Would you care to explain it to me? Imo 401.json would be better, as there already is support for 401.jpg as well.

tijmenstor avatar Apr 13 '20 11:04 tijmenstor

Hi @Tijmen34

There are no separate pages. Only the index file. HTTP Cats is an image API, so when you go to https://http.cat/500 you are redirected (by nginx rules) to the actual image file. That's why this enhancement is a bit more complicated than it should.

rogeriopvl avatar Apr 14 '20 11:04 rogeriopvl

@Tijmen34 and yes, one workaround could be using extensions like the example you provided. So if you open a PR with a json file for each status image, I'll be glad to merge it and adapt the Nginx configuration to serve that when the extension is .json. It may even be possible to also do it with the Accept header (depends on how flexible nginx config is).

rogeriopvl avatar Apr 14 '20 11:04 rogeriopvl

this snippit will pull http status codes from the wikipedia page of List of HTTP Status Codes, and builds a json file for each one. (note, required the 'pup' html command line parser)

curl https://en.wikipedia.org/wiki/List_of_HTTP_status_codes | pup -n 'div.mw-parser-output dl dt text{}' | sed -r 's/^([0-9]+) ([^(]+)(.*)/\1 {"code":\1, "text":\"\2\"}/;t;d' /tmp/a|while read -r code line; do echo $line > $code.json ; done

donpdonp avatar Apr 15 '20 17:04 donpdonp

It has been a long time, but I found this issue again :laughing: . I took note of @donpdonp script and created one that does not use pup and can simply be ran with bash. I can also add the actual files if that is more desirable or change bash -> sh to be in line with the other scripts. Let me know @rogeriopvl

tijmenstor avatar Mar 10 '21 17:03 tijmenstor