Package com.codingchili.core.protocol
Class Response
java.lang.Object
com.codingchili.core.protocol.Response
Helper methods for creating response messages.
Response messages should always contain a reference to the request.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic io.vertx.core.json.JsonObject
addHeaders(String target, String route, io.vertx.core.json.JsonObject message)
Adds response headers for a request.static io.vertx.core.buffer.Buffer
static io.vertx.core.buffer.Buffer
Converts the given message into a serializable format used to send messages back to clients.static io.vertx.core.json.JsonObject
error(String target, String route, ResponseStatus status, Throwable e)
Creates a response object given a response status and a throwable.static io.vertx.core.json.JsonObject
static io.vertx.core.json.JsonObject
Creates a json response message.static io.vertx.core.json.JsonObject
status(String target, String route, ResponseStatus status)
Creates a response object given a response status.
-
Constructor Details
-
Response
public Response()
-
-
Method Details
-
status
public static io.vertx.core.json.JsonObject status(String target, String route, ResponseStatus status)Creates a response object given a response status.- Parameters:
target
- the target header to set for the response.route
- the route header to set for the response.status
- the status to create the response from.- Returns:
- a JSON encoded response packed in a buffer.
-
error
public static io.vertx.core.json.JsonObject error(String target, String route, ResponseStatus status, Throwable e)Creates a response object given a response status and a throwable.- Parameters:
target
- the target header to set for the response.route
- the route header to set for the response.status
- the status to include in the response.e
- an exception that was the cause of an abnormal response status.- Returns:
- a JSON encoded response packed in a buffer.
-
buffer
- Parameters:
message
- the message to be converted to a buffer.- Returns:
- a message buffer.
- See Also:
buffer(Object)
-
buffer
Converts the given message into a serializable format used to send messages back to clients. Use this method when the context of a request is not available.- Parameters:
message
- the message to be converted.target
- the target header to set for the response.route
- the route header to set for the response.- Returns:
- a sendable json object without headers.
-
json
- Parameters:
message
- an object to be converted to a json message.- Returns:
- a json message with headers set.
- See Also:
json(Object)
-
json
Creates a json response message.- Parameters:
target
- the target header to set for the response.route
- the route header to set for the response.message
- the message to add request headers to.- Returns:
- a json object.
-
addHeaders
public static io.vertx.core.json.JsonObject addHeaders(String target, String route, io.vertx.core.json.JsonObject message)Adds response headers for a request.- Parameters:
target
- the target header to set for the response.route
- the route header to set for the response.message
- the response json object.- Returns:
- a json object with headers from the request added.
-