resthub / resthub-spring-stack

RESThub Spring stack
http://resthub.org/spring-stack.html
Other
121 stars 66 forks source link

Simplified HTTP Client API #84

Closed bclozel closed 12 years ago

bclozel commented 12 years ago

When dealing with async HTTP, request/response code can be far appart and decoupled. For me, using an API like Client.Response.jsonDeserialize can be awkward, since you may not know which content-type was used when the request was sent.

Introducing BodyReaders and BodyWriters

I know, it is JAX-RS like, but this is quite useful. RESThub's HTTP client supports JSON and XML out-of-the-box. Users can add other BodyWriters/BodyReaders to support other mediaTypes.

API changes

Response is no longer an inner class

import org.resthub.web.Client.Response;

is now:

import org.resthub.web.Response;

You don't need to specify the response format to deserialize it

future.get().jsonDeserialize(User.class);

is now:

future.get().getEntity(User.class);

Bugs fixed

JSON BodyReader matches standard json and vendor content-types

application/json application/vnd.atos.v2+json

XMLBodyReader matches standard xml and vendor content-types

application/xml application/vnd.atos.v2+xml

sdeleuze commented 12 years ago

Nice update, just a question about the getEntity() name. I wonder if we should use getEntity() or getResource() ? I am 50%/50% so it is up to you to choose the right one.

bclozel commented 12 years ago

Yep, getResource makes more sense.

loicfrering commented 12 years ago

:+1: maybe use resource() instead of getResource().