Skip to content

Instantly share code, notes, and snippets.

@andykuszyk
Created February 16, 2018 16:43
Show Gist options
  • Save andykuszyk/2fdea6f9af18ce987399b1108c9f21ae to your computer and use it in GitHub Desktop.
Save andykuszyk/2fdea6f9af18ce987399b1108c9f21ae to your computer and use it in GitHub Desktop.
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)
@andykuszyk
Copy link
Author

Run this script and then try hitting the API with:

curl -X POST http://localhost:8080/helloworld -d spam

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