Topics: Web Api
Oct 6, 2011 at 5:07 PM

What is the best practice to handle something like this:




And when calling this have different representations of the data returned to the client.

For example we might return a small set of data in one case, a little more data in another and possible all data with the third type but not modify the uri to do this.

I was going to do this in the headers something like a custom header. 

ReturnContent: small, medium or all

Is there a standard way of accomplishing this with existing http header standard?




Oct 6, 2011 at 8:32 PM

Not i am aware of.

The usual way people do it today is using query. For example, one can say i only want to get the top 10 records by using


If you don't want to change URL, you can add a custom header which includes the query top=10. Then you can register a message handler to modify the incoming URL to append this query. Then with QueryComposition feature we built in with web api, you can be able to return only 10 records.

hope this helps.


Oct 6, 2011 at 11:59 PM

Different representations of a resource are intended to make the data accessible to different clients.  They are not intended to return different amounts of data.  The only exception to this that I have seen is when a resource accessed by an authenticated user it may return additional information.

The translation from resource to representation should be a mechanical one.  It should not introduce more or less information depending on the representation type.

As hongmei mentioned you can use the query string to identify a new resource that has a different subset of the data, but you should not use the same URI.  Doing so would seriously limit your ability to do caching and reduces your ability to include hyperlinks that point to the exact resource that you want to present.  

There is also nothing wrong with doing http://site/data/all http://site/data/small and http://site/data/medium