Created
October 14, 2011 16:57
-
-
Save pneff/1287666 to your computer and use it in GitHub Desktop.
Echo REST service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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