rest services with many conditions

876 Views Asked by At

everyone =) I'm kind of novice in rest services, so I'm not sure if some features are possible. For instance I have a list of items and many ways to filter those before delevering to a client app. I'm using .net, linq & wcf rest service with json return format. Ways to filter the list:

.../Items/RecentOnes
.../Items/FilteredByDate
.../Items/ItemsWithCrashID('CrashId')
.../Items/ItemsWithValue('Value')

etc. And I need those filters to be called in one query. Like

.../Items/ItemsWithValue('Value')/RecentOnes/FilteredByDate

or

.../Items/FilteredByDate/ItemsWithCrashID('CrashID')/Recent

and other 14 possible combinations. (As you see, the order of the filters shouldn't matter)

My question is - Is it possible to write those 4 services somehow, to make all those combinations work?

Or the only way to do so is to write a single service with 4 params, like

.../Items?recentOnes=true&FIlteredByDate=false&CrashID=&Value=somevalue ? 

Thanks in advance =)

1

There are 1 best solutions below

0
On

Nice question! As restful web services used url as resources representation, e.g:

.../items          =>             get all items
.../items/1        =>             get an item which id == 1
.../items/1/edit   =>             edit an item which id == 1
.../items?value='computer' =>     get all items which value == 'computer'

so you can see that you url:

 .../Items/ItemsWithValue('Value')...

It's not represented to any specific resource at all. It seems like you are looking for some items, which is filtered by value. It's like a search. So your second choice is better, use any thing you want to filter as query string.