Introduktion till FastAPI
Matt Eckerle
Software and Data Engineering Leader
HTTP-protokollet – flera typer av operationer
Exempel: https://www.google.com:80/search?q=fastapi
De viktigaste delarna i en GET-förfrågan:
www.google.com80 (standard)/search?q=fastapiDen enklaste FastAPI-applikationen:
from fastapi import FastAPI# Instantiate app app = FastAPI()# Handle get requests to root @app.get("/") def root(): return {"message": "Hello World"}
Viktiga cURL-alternativ:
$ 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
Exempelanvändning:
$ curl http://localhost:8000
{"message":"Hello World"}
Ny endpoint:
@app.get("/hello")
def hello(name: str = "Alan"):
return {"message": f"Hello {name}"}
Inget namn i förfrågan:

Namn i förfrågan:

Introduktion till FastAPI