lokesh
lokesh

Reputation: 1

Why Rest End point is not showing any json data while using POST method in POSTMAN application?

I am trying to implement sample spring boot project and to ensure my endpoints are working properly, i'm using POSTMAN. When using POSTMAN , I am not able to see the response(i.e in Pretty) for a POST request. But the Status is 200 OK and I am able to see the result using GET request.

No Pretty response for POST request

GET Response ensuring that the previous POST request works fine

And my controller code is the following

@PostMapping("/message")
public Message createMessage(@RequestBody Message message)
{
      return service.createMessage(message);
}

Can anyone help me to find out why I am not able to see the result while using POST method please?

Upvotes: 0

Views: 608

Answers (2)

mama
mama

Reputation: 2227

Like Rafael says it is good to return a Response with the object entity. I haven't been working with Spring myself but with JavaEE and in JavaEE it is perfectly possible to return the object directly without using a Response. I use Responses anyways though, because it is much nicer to work with, and you can create your own custom responses and status codes.

Maybe check if your createUser service actually returns a message.

Upvotes: 1

Rafael Coelho
Rafael Coelho

Reputation: 308

I don't know much about Spring, but usually what works for me is using a ResponseEntity as the object returned by the function. Also, maybe you should use @RestController as the annotation to your class controller

@PostMapping("/message")
public ResponseEntity<Message> createMessage(@RequestBody Message message)
{
      Message msg = service.createMessage(message);
      return ResponseEntity.ok(msg);
}

Upvotes: 0

Related Questions