Table of Content
Fastapi is an another most popular framework of python for building powerful web api's just like Django. FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints. python for building powerful web api's just like Django. FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints.
Installation
Before move to create our first api, let's install these two required dependencies.
Let's create an API
Now create a main.py file and open it in any code editor.
- from fastapi import FastAPI
- app = FastAPI()
- @app.get("/")
- def read_root():
- return {"Hello": "World"}
Run the Server
To start the development server just hit this command in your terminal.
It will start the development server on the default port 8000
If you want to change the port you can add --port <portnumber>
Check the output
Interactive API docs by Swagger UI
If you want to see the automatic interactive API documentation provide by (Swagger UI)
Alternative API docs by ReDocs
If you want to see the automatic interactive API documentation provide by (ReDoc)
Conclusion
That's it, We have created our first basic and simple api using fastAPI. You can create more powerful api using FastAPI, check it out the fastAPI docs