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 入門