
In this post, I will introduce FastAPI by contrasting the implementation of various common use-cases in both Flask and FastAPI. The added benefit of automatic data validation, documentation generation and baked-in best-practices such as pydantic schemas and python typing makes this a strong choice for future projects. A parameter can be a string (text) like this: /product/cookie. Parameters can be used when creating routes. It was very easy to pick up FastAPI coming from Flask and I was able to get things up and running in just a few hours. The output of the function helloworld() is shown in your browser. I recently decided to give FastAPI a spin by porting a production Flask project. from flask import request app. The default is 'GET' if name 'main' is a special variable in Python which takes the value of the script name. You can change this behavior by supplying the methods argument to the route () decorator. app.route ('/hello/', methods 'GET', 'POST') We use the decorator to tell Flask what URL should trigger the function. It may also include the templates and static files that will be served. By default, routes only respond to GET requests.

While Flask has become the de-facto choice for API development in Machine Learning projects, there is a new framework called FastAPI that has been getting a lot of community traction. This blueprint would define the views for routes like /admin/login and /admin/dashboard.
