2

How can I return HTTP response with status code 202?

I couldn't find any reference for it in Spring Boot documentation.

3 Answers 3

8

Return HTTPStatus ACCEPTED, e.g:

 return new ResponseEntity<>(HttpStatus.ACCEPTED);

202 Accepted.

Sign up to request clarification or add additional context in comments.

Comments

2

You can do like this (I am using kotlin) :

return ResponseEntity.accepted().body(OrderResponse().order(order))

OR Easy way is:

    return ResponseEntity.status(HttpStatus.CREATED).body(OrderResponse().order(order))

ResponseEntity.accepted returns 202 ResponseEntity.created returns 201 and so on

Comments

-1
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(value=HttpStatus.NOT_FOUND, reason="No Article found with this Article Number.")
public class NoArticleFoundException extends RuntimeException{

    private static final long serialVersionUID =3935230281455340039L;
}

Instead of writing NOT_FOUND , you can write ACCEPTED and give some text in reason field. And then call this method from another class or when ever required. (extends part is not required)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.