Batch reads on multiple resources

79 views
Skip to first unread message

Felipe S.

unread,
Oct 28, 2012, 5:33:13 PM10/28/12
to api-...@googlegroups.com
Hi everyone,

I am working on a generic store for JSON using a RESTful API.
Basically you can PUT any JSON to our store and it will be sliced up so you can retrive it entirely or only slices of.
Now we one of our clients wondered if we could offer bachted READs on different section of this resource hierarchy.

Here is an example:

PUT /mydata

    "user" : {
                     "name" : "John",
                     "surname" : "Doe",
                     "age" : 22
                 },
    "permissions" : [READ,WRITE, DELETE],
    "session" : {
                      "cookie" : "asdasdjas",
                      "history" {
                                       "somekey" : "somevalue",
                                        "somekey2" : "somevalue",
                      }
}

When the user does a GET on /mydata he will receive exactly the JSON as above.
If he does a GET on /mydata/session/history he will receive
{
     "somekey" : "somevalue",
     "somekey2" : "somevalue",
}


Now he knows he has to get the 'user' object and the '/sessions/history' object from the same 'mydata' object.

I was wondering what were good patterns to allow this?
The only clean idea had was to use matrix params for filtering, as in GET /mydata;filter=user;filter=sessions/history
This would return 
{
      "user" : {
                     "name" : "John",
                     "surname" : "Doe",
                     "age" : 22
                 },
        "history" {
                                       "somekey" : "somevalue",
                                        "somekey2" : "somevalue",
                      }
}

What do you think? How would you approach such a task?

Cheers,
Felipe
                
   


Phil Jackson

unread,
Oct 29, 2012, 11:27:37 AM10/29/12
to api-...@googlegroups.com
Hey, Felipe,

If I were you I wouldn't try to do the deconstruction in the
path. Personally I would implement something like an XPath query as a
parameter like so:

/your/url/to/get/the/data?query=/address[3].street_name

Cheers,
Phil
--
http://apiaxle.com - A locally hosted API proxy
> --
> You received this message because you are subscribed to the Google Groups "API Craft" group.
> To unsubscribe from this group, send email to api-craft+...@googlegroups.com.
> Visit this group at http://groups.google.com/group/api-craft?hl=en.
>
>
Reply all
Reply to author
Forward
0 new messages