= Flask(__name__) # Create a new Flask instance @app.route(“/“) # Flask routing system def index(): # Your view return "Hello World” if __name__ == "__main__": app.run() # Run development server
methods=[‘POST']) # You can specific methods for every view def index(): # create a dict with request data data = request.json user = request.json[‘user’] … … … return "I got your data !” if __name__ == "__main__": app.run()
"This is a GET request" def post(self): return "This is a POST request" def put(self): return "This is a PUT request" def delete(self): return "This is a DELETE request” app.add_url_rule('/', view_func=UserAPI.as_view('users'))
a function to run before request handlers • before_first_request: is similar, but only once at start • after_request: registers a function to run after request handlers run • teardown_request: registers a function to run after request handlers run, even if they throw an exception • errorhandler: defines a custom error handler 22