Created
September 24, 2016 14:08
-
-
Save biancarosa/09df0cff9b0943982a870e07a05ef396 to your computer and use it in GitHub Desktop.
Falcon sample app (2 resources)
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
| # app.py | |
| import falcon | |
| import json | |
| class SongsResource: | |
| def on_get(self, req, resp): | |
| songs = [ | |
| { | |
| "title": "Your Song", "artist": "Elton John" | |
| }, | |
| { | |
| "title": "I Want To Break Free", "artist": "Queen" | |
| } | |
| ] | |
| resp.body = json.dumps(songs) | |
| class SongResource: | |
| def on_get(self, req, resp): | |
| song = { | |
| "title": "Your Song", "artist": "Elton John" | |
| } | |
| resp.body = json.dumps(song) | |
| api = falcon.API() | |
| api.add_route('/songs', SongsResource()) | |
| api.add_route('/song', SongResource()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment