public class

ResponseEntity

extends HttpEntity<T>
java.lang.Object
   ↳ org.springframework.http.HttpEntity<T>
     ↳ org.springframework.http.ResponseEntity<T>

Class Overview

Extension of HttpEntity that adds a HttpStatus status code.

Returned by getForEntity(String, Class, Object...):

 ResponseEntity<String> entity = template.getForEntity("http://example.com", String.class);
 String body = entity.getBody();
 MediaType contentType = entity.getHeaders().getContentType();
 HttpStatus statusCode = entity.getStatusCode();
 

Can also be used in Spring MVC, as a return value from a @Controller method:

 @RequestMapping("/handle")
 public ResponseEntity<String> handle() {
   HttpHeaders responseHeaders = new HttpHeaders();
   responseHeaders.set("MyResponseHeader", "MyValue");
   return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
 }
 

See Also

Summary

[Expand]
Inherited Fields
From class org.springframework.http.HttpEntity
Public Constructors
ResponseEntity(HttpStatus statusCode)
Create a new ResponseEntity with the given status code, and no body nor headers.
ResponseEntity(T body, HttpStatus statusCode)
Create a new ResponseEntity with the given body and status code, and no headers.
ResponseEntity(MultiValueMap<StringString> headers, HttpStatus statusCode)
Create a new HttpEntity with the given headers and status code, and no body.
ResponseEntity(T body, MultiValueMap<StringString> headers, HttpStatus statusCode)
Create a new HttpEntity with the given body, headers, and status code.
Public Methods
HttpStatus getStatusCode()
Return the HTTP status code of the response.
[Expand]
Inherited Methods
From class org.springframework.http.HttpEntity
From class java.lang.Object

Public Constructors

public ResponseEntity (HttpStatus statusCode)

Create a new ResponseEntity with the given status code, and no body nor headers.

Parameters
statusCode the status code

public ResponseEntity (T body, HttpStatus statusCode)

Create a new ResponseEntity with the given body and status code, and no headers.

Parameters
body the entity body
statusCode the status code

public ResponseEntity (MultiValueMap<StringString> headers, HttpStatus statusCode)

Create a new HttpEntity with the given headers and status code, and no body.

Parameters
headers the entity headers
statusCode the status code

public ResponseEntity (T body, MultiValueMap<StringString> headers, HttpStatus statusCode)

Create a new HttpEntity with the given body, headers, and status code.

Parameters
body the entity body
headers the entity headers
statusCode the status code

Public Methods

public HttpStatus getStatusCode ()

Return the HTTP status code of the response.

Returns
  • the HTTP status as an HttpStatus enum value