Skip to content

Instantly share code, notes, and snippets.

@kmila
Forked from nitaku/README.md
Created November 11, 2015 18:57
Show Gist options
  • Select an option

  • Save kmila/b9f14310b2f5b49c3e5f to your computer and use it in GitHub Desktop.

Select an option

Save kmila/b9f14310b2f5b49c3e5f to your computer and use it in GitHub Desktop.
Minimal JSON HTTP server in python

A minimal HTTP server in python. It sends a JSON Hello World for GET requests, and echoes back JSON for POST requests.

python server.py 8009 Starting httpd on port 8009...

curl http://localhost:8009 {"received": "ok", "hello": "world"}

curl --data "{"this":"is a test"}" --header "Content-Type: application/json" http://localhost:8009 {"this": "is a test", "received": "ok"}

Adapted from this Gist, with the addition of code for reading the request body taken from this article.

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