Query Parameters on Server
from fastapi import FastAPI
app = FastAPI()
fake_items_db = [
{
"id": 1,
"name": "Item 1"
"description": "Item 1 description"
},
{
"id": 2,
"name": "Item 2"
"description": "Item 2 description"
}
]
# example.com/items/?skip=0&limit=10
@app.get("/items/")
async def read_item(skip: int = 0, limit: int = 10):
return fake_items_db[skip : skip + limit]
Query Parameters on Requests
import requests
url = "https://maps.googleapis.com/maps/api/directions/json"
params = dict(
origin="Seattle,WA",
destination="San+Francisco,CA",
waypoints="Portland,OR",
sensor="false"
)
# translates to URL: https://maps.googleapis.com/maps/api/directions/json?origin=Seattle,WA&destination=San+Francisco,CA&waypoints=Portland,OR&sensor=false
response = requests.get(url, json=params)
data = response.json()