0

Am migrating a WebApi project (from preview version aka WCF WebApi to final release aka ASP.NET MVC4 WebApi).

In WCF WebApi, URI templates were defined for all services operations, like:

[WebGet(UriTemplate = "{movieGenreId}/movies")]

Bare I mind I have tens of those in the project. How do I translate this to MVC4 WebApi without having to register tens of entries in the Route table?

JasCav
  • 34,458
  • 20
  • 113
  • 170
kabaros
  • 5,083
  • 2
  • 22
  • 35

1 Answers1

1

You could go with the excellent attribute routing for Web API project:

It should be almost as easy as search and replace to convert UriTemplates to Attribute Routing.

If you are not willing to include the attribute routing library in your project, unfortunately the only other way is - as you said - registering tens of routes.

Filip W
  • 27,097
  • 6
  • 95
  • 82
  • thanks for this gem Filip. Is there any downside to using this library, slowness for example? – kabaros Oct 18 '12 at 15:49
  • 1
    not really, it doesn't do things much different than original UriTemplate did. I know for a fact that stackoverflow uses Attribute Routing (not this particular library but their own implementation, but still). – Filip W Oct 18 '12 at 16:49