2

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 =)

dan radu
  • 2,772
  • 4
  • 18
  • 23
Vital
  • 91
  • 1
  • 6
  • One of the advantages of using REST is the the ability to format URLs based on the service method parameters. So, the latest format looks "RESTful". If you want to use multiple filters, you can use a condition object and pass the string representation to the service: `../Items?condString={condString}`. The condition object can have properties like filter name, value, comparison operator, negation, and a list of child conditions. The parent condition is linked with with the child conditions via logical operators (`AND`, `OR`). – dan radu May 29 '12 at 06:39

1 Answers1

2

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.

Someth Victory
  • 4,492
  • 2
  • 23
  • 27