Skip to content

Instantly share code, notes, and snippets.

@andykuszyk
Created February 16, 2018 16:43
Show Gist options
  • Select an option

  • Save andykuszyk/2fdea6f9af18ce987399b1108c9f21ae to your computer and use it in GitHub Desktop.

Select an option

Save andykuszyk/2fdea6f9af18ce987399b1108c9f21ae to your computer and use it in GitHub Desktop.

Revisions

  1. andykuszyk created this gist Feb 16, 2018.
    20 changes: 20 additions & 0 deletions falcon-template.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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)