Here is my Spring Controller with the @PatchMapping :
@PatchMapping("/mode/{numClient}")
public Response<Object> mode(
@PathVariable Integer numClient,
@RequestBody ModeEnum mode,
@RequestHeader(name = "Authorization") String bearer
) throws BusinessException, NoSuchElementException {
// Code here
}
With my ModeEnum that looks like this :
public enum ModeEnum {
@JsonProperty("A")
AUTOMATIQUE('A'),
@JsonProperty("M")
MANUEL('M');
private final Character mode;
private ModeEnum(Character mode) {
this.mode = mode;
}
public Character getMode() {
return this.mode;
}
}
I use Angular as my frontend framework and this line of code
this.http.patch(`${url}/${numClient}`, {mode})
send this within the body :
{
"mode": "M"
}
and it works !
Now, when I try to send the same thing with Postman (or the code Postman generate), it doesn't work, I have a 400 bad request :
What I tried :
But none of them worked so I'm running out of ideas :(
You're not sending the Authorization
RequestHeader
from postman. Given that you've defined this in your handler, you either need to add required = false
, or pass the Authorization
header, otherwise you'll get a 400.