Issue
The following is a generic "Send an email to a user" endpoint, in a java application with SpringBoot framework.
src="https://i.stack.imgur.com/p4ts4.png" alt="enter image description here" />
Hitting it manually with Postman works as intended, but hitting it from the mobile frontend (largely react JS based) with the following JSON:
{recipientAddress: '[email protected]', subjectLine: 'a', messageBody: 's'}
Throws the following error:
Required request body is missing: public boolean
[. . .].Controllers.API.ApplicationUserController.sendEmail([. . .].Models.DTOs.EmailDTO)
I don't know where this would be coming from, as the RequestBody does not have a boolean, and the DTO it does request also does not have a boolean anywhere in it. The only boolean involved is the return value, but that wouldn't be relevant to the exception in question.
Solution
you should not use GET with payload as {recipientAddress: '[email protected]',...}
you can either:
- change
@GetMapping("/SendEmail")
to@PostMapping("/SendEmail")
and send an object (don't forgetcontent-type
header)
curl -X POST http://localhost:8080/SendEmail -d '{"recipientAddress": "[email protected]", "subjectLine": "a", "messageBody": "s"}' -H 'Content-Type: application/json'
(on postman make sure to change http method to POST)
- keep
@GetMapping
but break you payload into query params:
curl "http://localhost:8080/[email protected]&subjectLine=a&messageBody=s"
(assuming localhost:8080)
last you did not specify if you use class level annotation @RestController
or @Controller
, if you use @Controller
- you should also add @ResponseBody
on method level (use @RestController
if you can)
Answered By - ezer
Answer Checked By - Gilberto Lyons (JavaFixing Admin)