Reputation: 2236
We got a Web API webservice with entity framework and accept JSON calls.
We have a call named: GetResidents which lists all residents. We would like to have an extra parameter (hash) which allows the caller to filter the results on the server.
Like this:
{"filter":{
"and":{
"age":{
"less_than":80,
"greater_than":60
}
},
{
"active":{
"eq":true
}
}
In RoR in the past I've used this gem which works great: https://github.com/QutBioacoustics/baw-server/wiki/Rails-API-Spec:-Filtering Does something similar exist in WebAPI?
Thanks for any feedback.
Upvotes: 1
Views: 108
Reputation: 1887
Use OData. Here is documentation link. Basic example:
public class ResidentsController : ApiController
{
[Queryable]
public IQueryable<Resident> GetResidents() {}
}
For your json:
http://localhost/api/residents?$filter=age lt 80 and age gt 60 and active eq true
Upvotes: 1