Reputation: 71
I am using .net MVC Web API project template. This is my Get method in customer controller:
public IQueryable<Customer> Get()
{
CustomerRepository customer = new CustomerRepository ();
IQueryable<Customer> customer = lr.GetCustomer();
return data;
}
How can I add the content range headers along with data returned?:
content-range: item 0-9/100
**EDIT
I changed it to return HttpResponseMessage but still unsure about setting the content-range item. Not sure if I hard code "item 0-9/100" or if there is mechanism to know how many items to return?
public HttpResponseMessage Get()
{
CustomerRepository lr = new CustomerRepository();
IQueryable<Customer> data = lr.GetCustomer();
var resp = new HttpResponseMessage(HttpStatusCode.OK);
resp.Content = new ObjectContent<IQueryable<Customer>>(data, new JsonMediaTypeFormatter());
resp.Headers.Add("Content-Range", ???????)
return resp;
}
Upvotes: 1
Views: 1468
Reputation: 593
Answer to edited question.
The Content range header refers an index of the results returned in the Http Response. Item 0-9/100 means the response contains the first 10 items (indexes 0,1,2,3,4,5,6,7,8,9) of the 100 total.
It would make sense to return the index that matches the results returned from your method. You will need to determine what indexes are represented in your IQueryable<Customer> customer
object and fill out the header appropriately.
Upvotes: 0