uk.co.caeldev.spring.mvc.ResponseEntityBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-mvc-utils Show documentation
Show all versions of spring-mvc-utils Show documentation
Library with severals classes that might help with your REST API
The newest version!
package uk.co.caeldev.spring.mvc;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
public class ResponseEntityBuilder {
private HttpStatus statusCode;
private T resource;
private HttpHeaders headers = new HttpHeaders();
ResponseEntityBuilder() {
}
public static ResponseEntityBuilder responseEntityBuilder() {
return new ResponseEntityBuilder<>();
}
public ResponseEntityBuilder statusCode(final HttpStatus statusCode) {
this.statusCode = statusCode;
return this;
}
public ResponseEntityBuilder entity(final T resource) {
this.resource = resource;
return this;
}
public ResponseEntityBuilder header(final String key, final String value) {
headers.add(key, value);
return this;
}
public ResponseEntity build() {
return new ResponseEntity<>(resource, headers, statusCode);
}
}