Specification for query RESTFul resources using offset, limit & total
by Bruno Oliveira
Morning everybody.
Daniel has already implemented a lot of cool stuff on AeroGear controller for pagination. For this reason I created this Jira to see if the implementation matches our expectations on the client side (https://issues.jboss.org/browse/AEROGEAR-814).
For example, currently the headers are returning something like it:
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Content-Length: 160 AG-Paging-Offset: 0 AG-Paging-Limit: 4 AG-Paging-Total: 4 AG-Links-Next: cars?offset=1&limit=4 AG-Links-Last: cars?offset=3&limit=4 [ {"color":"Green","brand":"Audi","id":1}, {"color":"White","brand":"Audi","id":2}, {"color":"Black","brand":"Audi","id":3}, {"color":"Black","brand":"BMW","id":4} ]
Question, do we really need AG-Links-Next and AG-Links-Last. If I know about the total and I have the fields limit and offset, looks like 'Next' and 'Last' are useless. Am I wrong? I was wondering about something like this http://www.redmine.org/projects/redmine/wiki/Rest_api#Collection-resource...
--
"The measure of a man is what he does with power" - Plato
-
@abstractj
-
Volenti Nihil Difficile
10 years, 2 months
Paging Demo
by Daniel Bevenius
We talked about paging yesterday on IRC, and it was decided to add a paging
example to aerogear-controller-demo. What follows is an example to kick of
further discussion about what the example should look like.
AeroGear Controller Demo Paging Route
This page discusses
AEROGEAR-795<https://issues.jboss.org/browse/AEROGEAR-795> which
is about adding an example to aerogear-controller-demo to demonstrate
paging support so that the client libraries (Android, JavaScript, and iOS)
can be tested against it.
This is only a suggestion and the implementation and the names of the query
parameters can all be changed.
Use case
The example is using cars as the resource to interact with. To be able to
query we need something to query, so lets start by adding some cars by
posting.
Adding Cars
URL="http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo"
curl -i --header "Accept: application/json" -H "Content-type:
application/x-www-form-urlencoded" --data
"car.color=Black&car.brand=BMW" -X POST "$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" -X POST "$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" -X POST "$URL/cars"
curl -i --header "Accept: application/json" -H "Content-type:
application/x-www-form-urlencoded" --data
"car.color=Blue&car.brand=Saab" -X POST "$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 upon
redployment/restart of the server. So you only need to populate/post when
you've restared or redployed.
With the cars in place, we can now issue GET requests with paging query
parameters. 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 and
perPage. If these are not specified all cars will be returned.
Getting a page of Cars
URL="http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo"
curl -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 Cars
To get the next page you can follow the next link:
URL="http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo"
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 Cars
URL="http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo"
curl -i --header "Accept: application/json" "$URL/cars"
Get a single Car
URL="http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo"
curl -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 <https://gist.github.com/4147473>
10 years, 2 months
Re: [aerogear-dev] Contributing guidelines
by Kris Borchers
Sent from my Android phone using TouchDown (www.nitrodesk.com)
-----Original Message-----
From: Douglas Campos [qmx(a)qmx.me]
Received: Saturday, 12 Jan 2013, 9:25am
To: AeroGear Developer Mailing List [aerogear-dev(a)lists.jboss.org]
Subject: Re: [aerogear-dev] Contributing guidelines
On 12/01/2013, at 08:02, Daniel Bevenius <daniel.bevenius(a)gmail.com> wrote:
> +1 If it only contains information specific to the project in question. We could add a link to http://aerogear.org/docs/guides/Contributing/ in that file for the information that is common to all projects.
That was exactly what I was thinking. If we need to update this info, let it be on just one place.
+1
>
>
> On 11 January 2013 20:32, Bruno Oliveira <bruno(a)abstractj.org> wrote:
> Good morning slackers!
>
> Today in the early morning I asked on #aerogear about to update our projects with the CONTRIBUTING.md file (https://github.com/blog/1184-contributing-guidelines). qmx has raised some important concerns about the information duplicity and etc, but it took 15 minutes of my life to the PRs, so is not a big deal on closing it or merge. Follow your heart!
>
> What do you think?
>
>
> --
> "The measure of a man is what he does with power" - Plato
> -
> @abstractj
> -
> Volenti Nihil Difficile
>
> _______________________________________________
> aerogear-dev mailing list
> aerogear-dev(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/aerogear-dev
>
>
> _______________________________________________
> aerogear-dev mailing list
> aerogear-dev(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/aerogear-dev
_______________________________________________
aerogear-dev mailing list
aerogear-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/aerogear-dev
Sent from my Android phone using TouchDown (www.nitrodesk.com)
10 years, 2 months
Contributing guidelines
by Bruno Oliveira
Good morning slackers!
Today in the early morning I asked on #aerogear about to update our projects with the CONTRIBUTING.md file (https://github.com/blog/1184-contributing-guidelines). qmx has raised some important concerns about the information duplicity and etc, but it took 15 minutes of my life to the PRs, so is not a big deal on closing it or merge. Follow your heart!
What do you think?
--
"The measure of a man is what he does with power" - Plato
-
@abstractj
-
Volenti Nihil Difficile
10 years, 2 months