Вступ до FastAPI
Matt Eckerle
Software and Data Engineering Leader
Протокол HTTP — кілька типів операцій
Приклад: https://www.google.com:80/search?q=fastapi
Ключові частини GET-запиту:
www.google.com80 (типовий)/search?q=fastapiНайпростіший застосунок FastAPI:
from fastapi import FastAPI# Створити застосунок app = FastAPI()# Обробка GET-запитів до кореня @app.get("/") def root(): return {"message": "Hello World"}
Ключові параметри cURL:
$ curl -h
Usage: curl [options...] <url>
-v, --verbose Make the operation more talkative
-H, --header <header/@file> Pass custom header(s) to server
-d, --data <data> HTTP POST data
Приклад використання:
$ curl http://localhost:8000
{"message":"Hello World"}
Новий ендпойнт:
@app.get("/hello")
def hello(name: str = "Alan"):
return {"message": f"Hello {name}"}
Ім'я не вказано в запиті:

Ім'я вказано в запиті:

Вступ до FastAPI