This is my FastAPI script, I am doing basic lesson to make the POST API as simple as possible.
class Item(BaseModel):
test_param:str
@app.post('/myapi')
async def myapi(item:Item):
print(item)
return {"myapi":"OK"}
Then my script is like this:
var formData = new FormData();
formData.append('test_param',"1");
axios.post("/myapi",formData
,{headers: {'Content-Type': 'application/form-data'}}).then(res=>{
console.log(res);
});
When calling API, it shows the error 422 Unprocessable Entity
.
I guess there is some discrepancy in API and script, however where should I fix?