On Thursday, January 10, 2013 at 8:02 AM, Matthias Wessendorf wrote:
On Thu, Jan 10, 2013 at 10:11 AM, Daniel Bevenius<daniel.bevenius@gmail.com> wrote:For the demo purpose, we could bootstrap the list of cars during startup sowe don't need to manually add all the cars.Absolutely, that would be no problem.+1 - that would make it easier to test/developOn 10 January 2013 10:06, Sebastien Blanc <scm.blanc@gmail.com> wrote:Great !For the demo purpose, we could bootstrap the list of cars during startupso we don't need to manually add all the cars.SebOn Thu, Jan 10, 2013 at 10:02 AM, Daniel Bevenius<daniel.bevenius@gmail.com> wrote:We talked about paging yesterday on IRC, and it was decided to add apaging example to aerogear-controller-demo. What follows is an example tokick of further discussion about what the example should look like.AeroGear Controller Demo Paging RouteThis page discusses AEROGEAR-795 which is about adding an example toaerogear-controller-demo to demonstrate paging support so that the clientlibraries (Android, JavaScript, and iOS) can be tested against it.This is only a suggestion and the implementation and the names of thequery parameters can all be changed.Use caseThe example is using cars as the resource to interact with. To be able toquery we need something to query, so lets start by adding some cars byposting.Adding Carscurl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Black&car.brand=BMW" -XPOST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Red&car.brand=Ferrari"-X POST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Blue&car.brand=Skoda"-X POST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Green&car.brand=Audi"-X POST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Yello&car.brand=Opel"-X POST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Pink&car.brand=Mini" -XPOST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Gray&car.brand=Nissan"-X POST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Red&car.brand=Volvo" -XPOST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Blue&car.brand=Saab" -XPOST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Black&car.brand=Mazda"-X POST "$URL/cars"curl -i --header "Accept: application/json" -H "Content-type:application/x-www-form-urlencoded" --data "car.color=Yello&car.brand=Golf"-X POST "$URL/cars"The example uses an in-memory database so the data will be cleared uponredployment/restart of the server. So you only need to populate/post whenyou've restared or redployed.With the cars in place, we can now issue GET requests with paging queryparameters. The following route has been added to the demo:route().from("/cars").on(RequestMethod.GET).produces(MediaType.JSON.toString()).to(Cars.class).get(param("page", "0"), param("perPage", "-1"));From this we can see that there are two optional parameters, page andperPage. If these are not specified all cars will be returned.Getting a page of Carscurl -i --header "Accept: application/json" "$URL/cars?page=0&perPage=4"The request will return:{"metadata":{"page":0,"perPage":4},"cars":[{"color":"Black","brand":"BMW","id":1},{"color":"Red","brand":"Ferrari","id":2},{"color":"Blue","brand":"Skoda","id":3},{"color":"Green","brand":"Audi","id":4}],"links":{"first":"cars?page=0&page=4","previous":"cars?page=0&page=4","next":"cars?page=1&page=4"}}Getting the next page of CarsTo get the next page you can follow the next link:curl -i --header "Accept: application/json" "$URL/cars?page=1&perPage=4"{"metadata":{"page":1,"perPage":4},"cars":[{"color":"Yello","brand":"Opel","id":5},{"color":"Pink","brand":"Mini","id":6},{"color":"Gray","brand":"Nissan","id":7},{"color":"Red","brand":"Volvo","id":8}],"links":{"first":"cars?page=0&page=4","previous":"cars?page=0&page=4","next":"cars?page=2&page=4"}}Get all Carscurl -i --header "Accept: application/json" "$URL/cars"Get a single Carcurl -i --header "Accept: application/json" "$URL/cars/1"The request will return:{"color":"Black","brand":"BMW","id":1}Again, anything here can be changed, the name of the query parameters,the implementation, and what is returned.Reference:Paging Support in AeroGear Controller_______________________________________________aerogear-dev mailing list_______________________________________________aerogear-dev mailing list_______________________________________________aerogear-dev mailing list--Matthias Wessendorfsessions: http://www.slideshare.net/mwessendorftwitter: http://twitter.com/mwessendorf_______________________________________________aerogear-dev mailing list