-
Notifications
You must be signed in to change notification settings - Fork 140
[Z Proposal] JSend style support for idiomatic QBit REST Java support
JSend is a spec that has a lot of client library support. QBit supports this out of the box.
JSend is a application-level specification covering how JSON responses from REST services should be formatted.
There are lots of REST services out there providing JSON data and it is good to follow a standard way that is light weight and has industry support.
A basic JSend-compliant response is as simple as this:
{
status : "success",
data : {
"blogPost" : { "id" : 1, "title" : "A blog post",
"body" : "Some useful content" }
}
}
The body of the call will be in the data.
JSend style support can be turned on by setting the endpointServiceBuilder.setStandardJSONResponse(true)
.
There are three status types
- success
- fail
- error
Error means there was an error handling a call. Fail means there was some user data validation issue with the input parameters.
QBit's outputs the following fields for each * denotes optional.
- success (status, code, *data)
- fail (status, code, data, *message)
- error (status, code, message, *data)
QBit sends a small superset of attributes and idiomatically maps to the different exception styles.
If you mark an Exception with an @Fail
annotation then this exception denotes a Fail
. If this exception has a data
property then we will output that data
property as the data
attribute. If you do not specify a data property the message
property of the Exception will be used.
@Fail
class MyException {
...
All other exceptions are considered of type Error
, and no annotation is needed.
QBit searched for the properties data
, message
, code
, and uses these properties as expected.
If you do not specify a code (which you can only do by throwing an exception), the code is the HTTP code of the response.
The codes are as follows by default:
- 500 (Server Error) for errors
- 412 (precondition failure) for failures.
- 200 (Ok) if REST call returns a value and does not throw an exception.
- 202 (Accepted) if REST call does not return a value.
- 404 if service method is not found.
- 401 Unauthorized access.
If a code from a failure
or error
is numeric, and is between 400 and 599 then it will be the HTTP status code that is sent as well as the code of the JSend response. If the failure
or error
(denoted by throwing an exception) does not have a code then 412
and 500
will be used respectively.
Note it is also possible for a QBit REST endpoint to return an HttpResponse
in which case the body of the response become data, the code becomes code, and if the code is in the
- 0 to 399 range then it is a
"success"
responsestatus
, - and if the code is between 400 and 499, it is a
"failure"
responsestatus
, - and if the code is above 499, then it is a
status
of"error"
.
##Examples
{
status : "success",
code : 200,
data : {
"posts" : [
{ "id" : 1, "title" : "A blog post", "body" : "Some useful content" },
{ "id" : 2, "title" : "Another blog post", "body" : "More content" },
]
}
}
{
status : "success",
code : 202
}
{
"status" : "fail",
"code" : 500,
"data" : { "title" : "A title is required" }
}
{
"status" : "error",
"code" : 500,
"message" : "Unable to communicate with database"
}
{
"status" : "error",
"code" : "CUSTOM.CODE",
"message" : "Unable to communicate with database"
}
{
"status" : "error",
"code" : "401",
"message" : "Unable to communicate with database"
}
QBit Website What is Microservices Architecture?
QBit Java Micorservices lib tutorials
The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
Reactive Programming, Java Microservices, Rick Hightower
Java Microservices Architecture
[Microservice Service Discovery with Consul] (http://www.mammatustech.com/Microservice-Service-Discovery-with-Consul)
Microservices Service Discovery Tutorial with Consul
[Reactive Microservices] (http://www.mammatustech.com/reactive-microservices)
[High Speed Microservices] (http://www.mammatustech.com/high-speed-microservices)
Reactive Microservices Tutorial, using the Reactor
QBit is mentioned in the Restlet blog
All code is written using JetBrains Idea - the best IDE ever!
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting
Tutorials
- QBit tutorials
- Microservices Intro
- Microservice KPI Monitoring
- Microservice Batteries Included
- RESTful APIs
- QBit and Reakt Promises
- Resourceful REST
- Microservices Reactor
- Working with JSON maps and lists
__
Docs
Getting Started
- First REST Microservice
- REST Microservice Part 2
- ServiceQueue
- ServiceBundle
- ServiceEndpointServer
- REST with URI Params
- Simple Single Page App
Basics
- What is QBit?
- Detailed Overview of QBit
- High level overview
- Low-level HTTP and WebSocket
- Low level WebSocket
- HttpClient
- HTTP Request filter
- HTTP Proxy
- Queues and flushing
- Local Proxies
- ServiceQueue remote and local
- ManagedServiceBuilder, consul, StatsD, Swagger support
- Working with Service Pools
- Callback Builders
- Error Handling
- Health System
- Stats System
- Reactor callback coordination
- Early Service Examples
Concepts
REST
Callbacks and Reactor
Event Bus
Advanced
Integration
- Using QBit in Vert.x
- Reactor-Integrating with Cassandra
- Using QBit with Spring Boot
- SolrJ and service pools
- Swagger support
- MDC Support
- Reactive Streams
- Mesos, Docker, Heroku
- DNS SRV
QBit case studies
QBit 2 Roadmap
-- Related Projects
- QBit Reactive Microservices
- Reakt Reactive Java
- Reakt Guava Bridge
- QBit Extensions
- Reactive Microservices
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting