Введение в 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# Instantiate app app = FastAPI()# Handle get requests to root @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