Skip to content

Instantly share code, notes, and snippets.

@pneff
Created October 14, 2011 16:57
Show Gist options
  • Save pneff/1287666 to your computer and use it in GitHub Desktop.
Save pneff/1287666 to your computer and use it in GitHub Desktop.
Echo REST service
#!/usr/bin/env python
"""
echo web service: this is a simple WsgiService example.
"""
import datetime
from wsgiservice import Resource, get_app, mount, validate, expires
@mount('/echo')
class EchoResource(Resource):
"""Returns whatever the user inputs."""
@expires(datetime.timedelta(days=365))
@validate('echo', doc='String to return.')
def GET(self, echo):
return {'echo': echo}
# app is a WSGI app.
app = get_app(globals())
# Serve this service on port 8000
if __name__ == '__main__':
from wsgiref.simple_server import make_server
print "Running on port 8000. Visit http://localhost:8000/echo?echo=Hello"
make_server('', 8000, app).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment