Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Python example

  • Loading branch information...
commit 7393db502effb2b52c4be2dcbb1ad7f29f65bc57 1 parent 8bd4d22
@aeden authored
View
2  echo/python/echo/.gitignore
@@ -0,0 +1,2 @@
+env
+*.pyc
View
28 echo/python/echo/README.md
@@ -0,0 +1,28 @@
+# echo
+
+Web service written in python that parses and echoes JSON data.
+
+## Usage
+
+Activate the virtualenv:
+
+ virtualenv env
+ . env/bin/activate
+
+Download a WSGI server:
+
+ ./env/bin/easy_install gunicorn
+
+Run the service
+
+ ./env/bin/gunicorn -b 127.0.0.1:3000 app:app
+
+Call the service from curl:
+
+ curl -i "http://127.0.0.1:3000" -d '{"foo":"bar"}'
+
+## License
+
+Copyright (C) 2012 Anthony Eden
+
+Distributed under the MIT License.
View
5 echo/python/echo/app.py
@@ -0,0 +1,5 @@
+import json
+
+def app(env, start_response):
+ start_response('200 OK', [('Content-Type', 'application/json')])
+ return [json.dumps(json.loads(env['wsgi.input'].read(int(env.get('CONTENT_LENGTH')))))]
Please sign in to comment.
Something went wrong with that request. Please try again.