Úvod do FastAPI
Matt Eckerle
Software and Data Engineering Leader
Protokol HTTP – několik typů operací
Příklad: https://www.google.com:80/search?q=fastapi
Klíčové části požadavku GET:
www.google.com80 (výchozí)/search?q=fastapiNejjednodušší aplikace FastAPI:
from fastapi import FastAPI# Vytvoření aplikace app = FastAPI()# Obsluha GET na kořenu @app.get("/") def root(): return {"message": "Hello World"}
Klíčové volby 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
Ukázka použití:
$ curl http://localhost:8000
{"message":"Hello World"}
Nový endpoint:
@app.get("/hello")
def hello(name: str = "Alan"):
return {"message": f"Hello {name}"}
Jméno není v požadavku:

Jméno je v požadavku:

Úvod do FastAPI