Home > OS >  422 Error Code wenn sending a Post Request from Angular Frontend zu FastAPI Backend
422 Error Code wenn sending a Post Request from Angular Frontend zu FastAPI Backend

Time:10-27

I send a Post Request from angular frontend to an fastAPI backend. but the Backend gives back an 422 error code. Thats the Request:

 public submit(): any{
this.httpClient.post<any>(
  this.endpoint,
  this.data
).subscribe()

}

export interface FormLogin {
  readonly data: string;
}

And thats the backend:

    @app.post('/login')
    def create_login(login: Login):
    db.append(login.dict())
       return db

    class Login(BaseModel):
    data: str

CodePudding user response:

This will resolve your issue, just inform backend you are sending data in JSON format.

 public submit(): any{
    const headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    this.httpClient.post<any>(
        this.endpoint,
        this.data, {headers: headers}).subscribe((response)=> {
    });

}
  • Related