By defining nodes: ... = Header(default=None)
, you tell FastAPI that the values of the nodes
parameter should be extracted from the request headers.
FastAPI supports headers as single values: e.g. extracting the value of the User-Agent
header with user_agent: str = Header()
.
It also supports extracting lists of values from headers, if headers are specified multiple times (see https://fastapi.tiangolo.com/lo/tutorial/header-params/).
However it doesn't support extracting lists of dictionaries from request headers.
How would you even model that in a request header?
What you probably want to do, is extract the nodes from the request body (probably as JSON).
The simple fix for it is just to remove the = Header(...)
part. If there is just one parameter, FastAPI assumes that this represents the body.
@app.post("/create_nodes/")
def post(nodes: List[Dict] | None):
return JSONResponse(nodes)