Skip to content
Advertisement

How to return CREATED status (201 HTTP) in ResponseEntity

There is a Spring-MVC application. In controllers, when returning the results of methods, I return via ResponseEntity<>. On success, I return (200 statutes) the OK-method. But when creating something, I would like to return the CREATED-method (201 status). I just can’t understand what kind of URL to ask in parentheses when calling through CREATED. How can this be implemented?

Now I have such an implementation:

JavaScript

I want to remake it like this to make it work(now it not work):

JavaScript

enter image description here

P.S. I don’t have a frontend at all. All through Swagger or PostMan.

Advertisement

Answer

Just return this way:

JavaScript

Making sure you have imported org.springframework.http.HttpStatus

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement