Closed bmeurant closed 12 years ago
I think that this is a nice step forward but still not RESTfull as "search" is not a resource. IMO the route should be:
/entity?page=X...
However it would require to return Object
instead of List<T>
or Page<T>
for the findAll
method...
Maybe we should just return Page
I've been looking into Spring HATEOAS for that. You can add links to your Resources for pagination, relations... But it kinda sucks to rely (again!) on inheritance, since you've got to extend Resource for that. Traits anyone?
I'm really wondering if we should have:
For HATEOAS concerns as well as relations and other things we never know how to manage, I think we should seriously considering using DTO.
Yet my main concern here is about the boilerplate Mapping code we would have to write to map Entities to DTO but the main advantage is total control on what we send over the wire.
+1
Maybe we should consider object mappers like Dozer. Or should we stick to dedicated DTO constructors?
The mappings via API look quite interesting in Dozer!
Concerning pagination, here is an interesting article related to Spring MVC: http://www.baeldung.com/2012/01/18/rest-pagination-in-spring/.
I like the Link HTTP header
solution but I don't know if common pagination libs will handle this.
For example, Backbone JS collection wrap the server response after a fetch and expose only response body:
// **parse** converts a response into the hash of attributes to be `set` on
// the model. The default implementation is just to pass the response along.
parse: function(resp, xhr) {
return resp;
},
To parse header, we will have to override collection.parse()
method (ex: http://stackoverflow.com/questions/9062605/how-to-handle-custom-response-in-backbone-model).
Fortunately, Backbone Paginator can handle this : it already overrides parse
and we could get an xhr object and do : xhr.getResponseHeader("Content-type");
for example.
So I think that we must check if common pagination libs (any language but mainly java and javascript) can handle this before or provide alternatives.
This pull request passes (merged 89e0987c into 562af449).