Created
February 16, 2018 16:43
-
-
Save andykuszyk/2fdea6f9af18ce987399b1108c9f21ae to your computer and use it in GitHub Desktop.
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
import falcon | |
import waitress | |
import json | |
class HelloWorldResource: | |
def on_post(self, req, resp): | |
content = req.stream.read().decode() | |
if content == 'spam': | |
resp.body = json.dumps('eggs') | |
elif content == 'foo': | |
resp.body = json.dumps('bar') | |
else: | |
resp.status = falcon.HTTP_404 | |
if __name__ == '__main__': | |
api = falcon.API() | |
api.add_route('/helloworld', HelloWorldResource()) | |
waitress.serve(api, host="0.0.0.0", port=8080, threads=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this script and then try hitting the API with: