tags:

views:

181

answers:

2

Our resources consists of dozens of fields (attributes). Some of our clients don't need all resource's properties. To save network payload we implemented a query string parameter to limit the resource properties. So for example, the next URL will return a collection of resources with all their fields:

http://myapp/myresources

But when the client needs only specific fields he can do that by calling:

http://myapp/myresources?fields=f1,f2,f13,f22

Our architect argues that this approach is not RESTful.

What do you think?

+1  A: 

It would be RESTful if you implemented it as new media types (representations) of the same resource. It would be an incomplete representation, but still, a representation. Let's say you have this resource:

/myapp/myresources

which is a collection of complete representations of some kind of resource. It's perfectly ok to have a different representation of the same collection. However, if you want it to be REST compliant, you should implement it as a new media type (format).

Then, you can query the collection with Accept header set to your desired media type, or you can use "media type in extension style" - eg. /myapp/myresources.f1_f2_f3.

Your situation is a bit tricky, since your media types would be invented on the fly, but I think it's not impossible.

Milan Novota
LiorH
You can add parameters to Accept header, too. So, your media type can look like this: xml/summary;fields=f1,f2... or in similar manner.
Milan Novota
@LiorH XML and JSON are semantic-free media types. To be RESTful, you need to provide your own defined media types. You can use JSON and XML as a base, but that alone is not sufficient. For example, look at ATOM, which uses XML.
Wahnfrieden
+1  A: 

The question goes away if you stop making the distinction between resources and fields.

If resource /myresource has two 'sub-resources' /myresource/f1 and /myresource/f2, then it makes sense to get both at once by specifying a list: /myresource/f1,f2.

Peter Hilton
No, because a URI has nothing to do with REST.
Wahnfrieden