Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion: json response #42

Open
donpdonp opened this issue Jan 29, 2020 · 6 comments · May be fixed by #96
Open

suggestion: json response #42

donpdonp opened this issue Jan 29, 2020 · 6 comments · May be fixed by #96

Comments

@donpdonp
Copy link

donpdonp commented Jan 29, 2020

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

@rogeriopvl
Copy link
Member

Hi @donpdonp ,

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

@tijmenstor
Copy link

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.

@rogeriopvl
Copy link
Member

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
Copy link
Member

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

@donpdonp
Copy link
Author

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

@tijmenstor
Copy link

It has been a long time, but I found this issue again 😆 . 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants