1
votes

So I am writing an API that will return OData but I have a problem with the default routing convention. Due compatibility reasons I can not use the default convention.

In other words, I need to change the routing from

/api/customers(1)/something

to

/api/costumers/1/something

Any reference or idea to help me? :)

Thanks

2
I forgot to mention: I am using OData v4Matheus da Rosa

2 Answers

2
votes

I think what you are looking is key-as-segment. It's not original supported in Web API OData. See https://github.com/OData/WebApi/issues/105

However, you can code a little bit to support it. For example:

Derived from DefaultODataPathHandler, implement the necessary function, enable the UriParser to support KeyAsSegment:

uriParser.UrlConventions = ODataUrlConventions.KeyAsSegment;

Hope it can help you.

0
votes

If you are using System.Web.OData, Version=5.9.0.0, this can be done by invoking the following extension method when configuring your service on startup:

using System.Web.OData.Extensions;
...
// This is just to show the type, this will likely come from the web app startup
HttpConfiguration config = new HttpConfiguration(); 
...
config.SetUrlConventions(ODataUrlConventions.KeyAsSegment);