Created
June 11, 2017 22:45
-
-
Save ruanbekker/765f9bc56fa0888c7e1e843ea3475a4a to your computer and use it in GitHub Desktop.
Basic API Server with Flask-Restful
This file contains 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
from flask import Flask | |
from flask_restful import Resource, Api | |
app = Flask(__name__) | |
api = Api(app) | |
class Colors(Resource): | |
def get(self): | |
return { | |
'colors': [ | |
'red', | |
'blue', | |
'green', | |
'yellow', | |
'orange' | |
] | |
} | |
class Cars(Resource): | |
def get(self): | |
return { | |
'bmw': { | |
'model': 'm3', | |
'type': 'sports', | |
'color': 'red' | |
}, | |
'audi': { | |
'model': 'tt', | |
'type': 'sports', | |
'color': 'white' | |
} | |
} | |
api.add_resource(Colors, '/api/colors/') | |
api.add_resource(Cars, '/api/cars/') | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment