Handling endpoints / requests with interesting parameter combinations

July 28, 2022

API:

@app.get("/items/")
async def read_items(q: Union[list[str], None] = Query(default=None)):
    query_items = {"q": q}
    return query_items

Get Request:

payload = {"composite_codes": ["FOGGDIFF_CMP", "FU1CAUT_CMP", "FU4DGF_CMP"]}
response = requests.get(self.url, params=payload)

Post Request:

query = """
query portfolios($codes: [String]!) {
    portfolios(
        query: {
            codes: $codes
        }
    )
}
"""
variables = {"codes": ["FOGGEQUI", "FOGGDYNA", "FOGGPRIV"]}
 
response = requests.post(
    url,
    json={
        "query": query,
        "variables": variables,
    },
)