2 ms·
Interesting, seems like the upcoming "Hello World" for API services :-) I also made a "return the HTTP code you request"-service like this, but with another de
by jschulenklopper 11y ago
Interesting, seems like the upcoming "Hello World" for API services :-)
I also made a "return the HTTP code you request"-service like this, but with another design choice than in this one and some others like http://httpbin.org/ http://httpbin.org/, https://httpstatuses.com/ https://httpstatuses.com/, http://httpstat.us/ http://httpstat.us/.
Instead of specifying the requested HTTP code in the URL path, I put the requested HTTP code in the URL query, basically ignoring the URL path. In that way, the URL path -- the resource identification in a REST-styled API -- can stay whatever you want as you're specifying the requested status code as query parameter. This made testing a program that uses resources in a REST API easier, as I don't need to rewrite the URL path, but just require to add a query parameter in my test code.
Example: instead of http://example.com/404 http://example.com/404 I request http://example.com/resource/id?response=404 http://example.com/resource/id?response=404 to get a 404 response. http://example.com/resource/another-id?response=200 http://example.com/resource/another-id?response=200 gets a 200 code.
- jschulenklopper 11y agoOh, and also other request types are specified in the URL query, such as a delayed response: http://example.com/resource/id?delay=0.5 http://example.com/resource/id?delay=0.5, which returns a 200 after 0.5 seconds. In this way, combining requested responses is also possible: http://example.com/resource/id?status=500&delay=2 http://example.com/resource/id?status=500&delay=2 to return a 500 after 2 seconds. I couldn't figure out if this behavior is also possible with services specifying the desired responses in the URL path.