Service result is a structural pattern for RESTful Web Services. This pattern provides a type safe and well structured response format. The surplus value is that you will always get a service-result regardless of whether the response is successful, failed, expected or an error. This is an example for a service-result:
{
"status": "successful",
"type": "ch.viascom.example.models.response.GetTasksResponse",
"content": [
{
"id": "3e99c7fb-0ed7-11e7-a7a5-0050569c3e5a",
"name": "Example Task"
}
],
"hash": "7bf9c04d1e9f8fe7995e4b8beeac1a4c830e7ea",
"destination": "ch.viascom.example.handler.TaskHandler",
"metadata": {
}
}
You can add service-result to your project by the following Maven or Gradle dependency.
<dependency>
<groupId>ch.viascom.groundwork</groupId>
<artifactId>service-result</artifactId>
<version>1.4</version>
</dependency>
compile 'ch.viascom.groundwork:service-result:1.4'
element | explanation |
---|---|
status | can be successful or failed and is the logical answer to the question: Did you got what you asked for? |
type | fully qualified name of the model |
content | your plain serialized information |
hash | hash of the content |
destination | information about where the response should go (useful for queues and streams) |
metadata | key-value pairs for additional related data |