
Httpstat.us: API for generating different HTTP codes. - kilian
http://httpstat.us/
======
elliottcarlson
18 lines of node.js to accomplish something similar - I use something similar
as a function in my node.js scripts to be able to send a generic error
template based on the code that I pass back to the function.

    
    
        var http = require('http');
        http.createServer(function (request, response)
        {
            var statusCode = request.url.substr(1, 3);
            response.writeHead(statusCode, { 'connection' : 'close', 'content-type' : 'text/html' });
            response.write('<html>');
            response.write('<head><title>' + statusCode + ' ' + http.STATUS_CODES[statusCode] + '</title></head>');
            response.write('<body bgcolor="white">');
            response.write('<center><h1>' + statusCode + ' ' + http.STATUS_CODES[statusCode] + '</h1></center>');
            response.write(' '.repeat(512));
            response.write('</body>');
            response.end('</html>');
        }).listen(8124, "0.0.0.0");
    
        String.prototype.repeat = function(num)
        {
            return new Array(num++).join(this);
        }

~~~
jsdalton
Here's a little something similar I whipped up using Flask (Python):

    
    
        import time
        from flask import Flask, make_response, request
        app = Flask(__name__)
    
        @app.route('/<int:status_code>')
        def return_status(status_code):
            response = make_response()
            response.status_code = status_code
            response.data = response.status
        
            sleep = request.args.get('sleep', None)
            if sleep is not None:
                time.sleep(int(sleep))
            return response
    
        if __name__ == '__main__':
            app.run(debug=True)
    

With a handy little feature, a "sleep" query string param that'll delay the
response for the given number of seconds, which I've used to test how a client
handles latency etc.

[BTW, looks like you're the Elliot Carlson I used to work with way back when.
Hope life is treating you well these days! :)]

~~~
elliottcarlson
Hah, indeed! Email me some time - x at sublim dot nl

------
kilian
I like how it implements "418 I'm a teapot" as well :)

~~~
JonnieCache
Except it doesn't actually, it returns 'Unknown Error.' Disappointed. Maybe
varnish isn't allowing it through?

    
    
        $ curl -v http://httpstat.us/418
        * About to connect() to httpstat.us port 80 (#0)
        *   Trying 75.101.145.87... connected
        * Connected to httpstat.us (75.101.145.87) port 80 (#0)
        > GET /418 HTTP/1.1
        > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
        > Host: httpstat.us
        > Accept: */*
        > 
        < HTTP/1.1 418 Unknown Error
        < Server: nginx/0.7.67
        < Date: Tue, 15 Feb 2011 16:46:59 GMT
        < Content-Type: text/plain
        < Connection: keep-alive
        < Access-Control-Allow-Origin: *
        < Content-Length: 16
        < X-Varnish: 1137499688
        < Age: 0
        < Via: 1.1 varnish
        < 
        * Connection #0 to host httpstat.us left intact
        * Closing connection #0
        418 I'm a Teapot

~~~
tatham
You're still getting a 418 response there, just not the right status
description.

Varnish is certainly stuffing us up a bit. There's a note about this at the
bottom of the page.

If I did this again, I wouldn't deploy it to Heroku for this reason.

------
arthurk
I did a similar experiment a few years ago. It's based on GAE and you can find
it here: <http://httpstatus.appspot.com/>

source code: <https://github.com/arthurk/httpstatus>

~~~
tatham
Nice! :)

Mostly, we wanted to play with some tech and we came across the domain name
httpstat.us which we just thought was cool.

------
ashishb4u
<http://httpstat.us/404> seems to dump HTML on my browser.

~~~
atuladhar
Yeah; it's sending back text/plain...

<http://httpstat.us/404>

HTTP/1.1 404 Not Found Server: nginx/0.7.67 Date: Tue, 15 Feb 2011 14:13:09
GMT Content-Type: text/plain Access-Control-Allow-Origin: * X-Varnish:
651017685 Age: 0 Via: 1.1 varnish Transfer-Encoding: chunked Proxy-Connection:
Keep-Alive Connection: Keep-Alive Content-Encoding: gzip

------
jrockway
I never realized how little browsers knew about http. Firefox treats
everything like 200, including things like 305. Odd.

~~~
steveklabnik
They don't support PUT or DELETE either, which means that people building
RESTful APIs have to fudge it. Ugly.

~~~
mccutchen
Recent-ish WebKit and Firefox browsers do support PUT and DELETE in XHR
requests. I'm pretty sure that any IE < 9 does not, not sure about IE 9 or
Opera (though I'd guess Opera does support those verbs).

~~~
tjpick
one major problem is HTML forms doesn't have a way to generate these.

~~~
jrockway
I could invent one pretty easily. Instead of <form action="post">, it could be
<form action="put">.

------
kodeninja
If you type <http://httpstat.us/1000>, it returns:

100 Unknown Status

~~~
eelco
To be fair, the website says: "If you send any other three digit number that's
not in that list, we'll return it too."

They seem to simply truncate the number. E.g.,
<http://httpstat.us/39487394587394857349587> returns "394 Unknown status", but
<http://httpstat.us/200129038123> will return "200 OK"

------
jonursenbach
On the subject of HTTP status codes, I wrote this a week or so ago because I
was always sick of having to look up status code definitions.

<https://github.com/jonursenbach/http-status-code-definitions>

------
awulf
Very useful, thanks! A nice addition would be random option like
<http://httpstat.us/random> or even <http://httpstat.us/?random=200+404>.

~~~
slace
That is a pretty neat idea, I'm looking into it now.

\--@slace (co-author of httpstat.us)

------
frytaz
<http://httpstat.us/000> shows Heroku Error

Oops, we seem to have a glitch in our system.

We've been notified; you might try reloading the page in a little while.

v 26026 2077752888

------
eelco
I wonder where they used CouchDB and Cloudant for (listed at the bottom of the
page).

~~~
cytzol
I was intrigued by all the linked technologies, too. I've spent a day or so
writing a site that I can't imagine being more than a few static pages, and
it's just running on nginx on this VPS I bought.

I can understand monitoring for a site that -has- to be up (otherwise testing
suites would start to break), but not the cloud database, let alone
programmable markup or managed hosting (Heroku). Surely all that extra
complexity is going to cost more in downtime than the time taken to set things
up manually?

~~~
mlmilleratmit
While we're honored to see that Cloudant plays a roll in the their app, I
imagine the real answer to your question is the phrase "Experiment" at the
bottom of the page. I imagine this is about learning/testing, not the most
optimized way to skin the cat.

~~~
tatham
You're correct - it was all one big experiment so we threw way more
technologies at it than we had to.

<http://isitbeerti.me> was another experiment of ours on the .NET platform

------
stdbrouw
Also interesting, if you're developing an API:
[http://blog.programmableweb.com/2010/08/16/writing-
bulletpro...](http://blog.programmableweb.com/2010/08/16/writing-bulletproof-
apps-with-api-errorpoints/)

------
petervandijck
Very nice :) Perhaps add links to other useful testing services on that page?

~~~
tatham
Suggestions?

~~~
pg
Please stop signing your posts.

------
KishoreKumar
Kindly, can any one tell me why would we need such a website?

