First the imports, this demo requires the flask_restful package.
Then we set up the Flask wsgi application object, app and the api wrapper, api.
>>> from flask import Flask
>>> from flask_restful import Resource, Api
>>> app = Flask(__name__)
>>> api = Api(app)We define a single HelloWorld resource, that responds with a simple json
object on a GET request.
>>> class HelloWorld(Resource):
... def get(self):
... return {'hello': 'world'}api.add_resource() wires the Resource class HelloWorld into the flask
router at /.
>>> api.add_resource(HelloWorld, '/')After we have created everything, we run the flask werkzeug server.
>>> if __name__ == '__main__':
... app.run()
Running without doctest's verbose mode looks like a normal flask server:
$ python -m doctest lit.md * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)With verbose mode: