Wprowadzenie do FastAPI
Matt Eckerle
Software and Data Engineering Leader
Protokół HTTP – kilka typów operacji
Przykład: https://www.google.com:80/search?q=fastapi
Główne elementy żądania GET:
www.google.com80 (domyślny)/search?q=fastapiNajprostsza aplikacja FastAPI:
from fastapi import FastAPI# Instantiate app app = FastAPI()# Handle get requests to root @app.get("/") def root(): return {"message": "Hello World"}
Kluczowe opcje 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
Przykład użycia:
$ curl http://localhost:8000
{"message":"Hello World"}
Nowy endpoint:
@app.get("/hello")
def hello(name: str = "Alan"):
return {"message": f"Hello {name}"}
Brak nazwy w żądaniu:

Nazwa w żądaniu:

Wprowadzenie do FastAPI