Introducere în FastAPI
Matt Eckerle
Software and Data Engineering Leader
Protocolul HTTP - mai multe tipuri de operațiuni
Exemplu: https://www.google.com:80/search?q=fastapi
Elementele cheie ale unei cereri GET:
www.google.com80 (implicit)/search?q=fastapiCea mai simplă aplicație FastAPI:
from fastapi import FastAPI# Instantiate app app = FastAPI()# Handle get requests to root @app.get("/") def root(): return {"message": "Hello World"}
Opțiuni cheie 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
Exemplu de utilizare:
$ curl http://localhost:8000
{"message":"Hello World"}
Endpoint nou:
@app.get("/hello")
def hello(name: str = "Alan"):
return {"message": f"Hello {name}"}
Fără nume în cerere:

Cu nume în cerere:

Introducere în FastAPI