Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created June 11, 2017 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanbekker/765f9bc56fa0888c7e1e843ea3475a4a to your computer and use it in GitHub Desktop.
Save ruanbekker/765f9bc56fa0888c7e1e843ea3475a4a to your computer and use it in GitHub Desktop.
Basic API Server with Flask-Restful
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