Reputation: 1900
I'm trying to override the OData queries..
I want to upgrade my application.
the OLD application get the User object like this:
http://localhost:12345/api/users/?$filter=userName eq 'test'
The NEW application will get the User object like this:
http://localhost:12345/api/users/?userName=test
I want to support the Old application, and to override the OData query ?$filter=...
With Overriding I can use the new method and return the right User object.
Is there a way to Override the OData query?
P.S: I need to keep the $top & $orderby OData queries untouched...
Thanks!!
Upvotes: 0
Views: 695
Reputation: 5275
WCF DS doesn´t provide a way to do that. However IIS can help you.
The idea is rewrite the url changing it for that that you need using the URL Rewrite module. For example, in you case you should specify that when IIS receives a request containing userName it rewrite it to use $filter instead.
<rewrite>
<rules>
<rule name="Compatibility with older versions" enabled="true" stopProcessing="true">
<match url="^api/users/?$userName eq (.*)" />
<action type="Rewrite" url="http://localhost:12345/api/users/?$filter={R:2}"/>
</rule>
</rules>
</rewrite>
Of course I didn´t test it in your application but that´s how we are doing it in our project to keep versions compatibility.
Your should read more about it because there are lots of thing you can do with that IIS module.
Upvotes: 2