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)=> {
});
}