Introduction to FastAPI
Matt Eckerle
Software and Data Engineering Leader
HTTP protocol - several types of operations
Example: https://www.google.com:80/search?q=fastapi
The key parts of a GET request are:
www.google.com
80
(default)/search
?q=fastapi
The simplest FastAPI application:
from fastapi import FastAPI
# Instantiate app app = FastAPI()
# Handle get requests to root @app.get("/") def root(): return {"message": "Hello World"}
Key cURL options:
$ 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
Example usage:
$ curl http://localhost:8000
{"message":"Hello World"}
New endpoint:
@app.get("/hello")
def hello(name: str = "Alan"):
return {"message": f"Hello {name}"}
Name not in request:
Name in request:
Introduction to FastAPI