https://github.com/mhered/fastapi_tutorial
https://github.com/mhered/fastapi_tutorial
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mhered/fastapi_tutorial
- Owner: mhered
- Created: 2022-09-11T22:00:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-11T23:50:20.000Z (over 3 years ago)
- Last Synced: 2025-12-29T07:21:09.416Z (5 months ago)
- Language: Python
- Size: 74.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
---
typora-copy-images-to: ../../../../../home/mhered/fastapi_tutorial/assets/images
---
# FastAPI tutorial
## Installation
```bash
$ pip install fastapi[all]
```
## Hello World in 7 steps
Create `main.py`:
```python
from fastapi import FastAPI # 1) import FastAPI
my_app = FastAPI() # 2) create a FastAPI instance in the variable my_app
@my_app.get("/") # 3) define a path operation decorator for GET requests to the URL "/"
async def root(): # 4) write the path operation function
return {"message": "Hello World!"} # 5) return the content
```
then 6) run this basic JSON server using `uvicorn` with:
```bash
$ uvicorn main:my_app --reload
INFO: Will watch for changes in these directories: ['/home/mhered/fastapi_tutorial']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [73948] using watchgod
INFO: Started server process [73950]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: 127.0.0.1:41690 - "GET / HTTP/1.1" 200 OK
```
and 7) open your browser at http://127.0.0.1:8000:

You also get interactive documentation at http://127.0.0.1:8000/docs:
