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"}
Endpoint ใหม่:
@app.get("/hello")
def hello(name: str = "Alan"):
return {"message": f"Hello {name}"}
ไม่ระบุชื่อในคำขอ:

ระบุชื่อในคำขอ:

FastAPI เบื้องต้น