Home > Software engineering >  Error in Angular with HTTPparams 422 (Unprocessable Entity) and FastAPI
Error in Angular with HTTPparams 422 (Unprocessable Entity) and FastAPI

Time:09-22

I have this url in backend and need pass c1 like a parameter, c1 is only an example, this method enable or disable an user and give back an "ok"

enter image description here

I copy here the method of the backend, i dont know if it's important to find the problem, it's done with FastAPI

@router.post("/enable_disable_account")
async def enable_disable_account(name: str, current_user: User = Security(get_current_user, scopes=["admin"])):           
result = await admin_db.enable_disable_account(name)
if result:
    return JSONResponse(status_code=status.HTTP_200_OK,
                        content='ok')

CodePudding user response:

this.http.post('http://127.0.0.1:8000/admin/enable_disable_account', params)

this line is incorrect.

Angular http client post method second parameter is body, and third parameter is options.

when you want to set query and pass params you need to pass as third parameter. and also you must to send as a object not just HttpParams. Angular Http Client API reference

this.http.post('http://127.0.0.1:8000/admin/enable_disable_account',null ,{
params: params
})
  • Related