Package com.adobe.granite.haf.api
Interface ApiResponseBuilder
An interface for creating ApiResponse instances. To create an ApiResponseBuilder instance use
ApiResponseBuilderFactory.createBuilder()
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build the ApiResponse instance with the values specified in this ApiRespoonseBuilder.Set the body to be returned in the response.setContentType
(String contentType) Set the content type of the body.Set an entity to be used as the response body.Set the HTTP statuswithChange
(Modification modification) Add a Modification to be returned in the changes section of the response.withHeader
(String key, String value) Set an HTTP header to be used in the response.withHeader
(String key, String[] values) Set an HTTP header with multiple values.
-
Method Details
-
setStatus
Set the HTTP status- Parameters:
code
- The status codemessage
- The status message- Returns:
- This ApiResponseBuilder instance
-
withHeader
Set an HTTP header to be used in the response. If a header with this key already exists it will be replaced with the value specified in this method.- Parameters:
key
- The HTTP header namevalue
- The HTTP header value- Returns:
- This ApiResponseBuilder instance
-
withHeader
Set an HTTP header with multiple values. If a header with this key already exists it will be replaced with the values specified in this method.- Parameters:
key
- The HTTP header namevalues
- The HTTP header values- Returns:
- This ApiResponseBuilder instance
-
setEntity
Set an entity to be used as the response body. The entity must be a Resource that can be interpreted by the HTTP API Framework- Parameters:
entity
- A resource to be used as the entity- Returns:
- This ApiResponseBuilder instance
-
setBody
Set the body to be returned in the response. The body must be an instance of CharSequence or a byte[]- Parameters:
body
- An instance of CharSequence or a byte[] to be used in the body of the response.- Returns:
- This ApiResponseBuilder instance
-
setContentType
Set the content type of the body.- Parameters:
contentType
- The content type.- Returns:
- This ApiResponseBuilder instance.
-
withChange
Add a Modification to be returned in the changes section of the response.- Parameters:
modification
- The Modification to be added.- Returns:
- This ApiResponseBuilder
-
build
ApiResponse build()Build the ApiResponse instance with the values specified in this ApiRespoonseBuilder.- Returns:
- The ApiResponse instance
-