Thursday, October 6, 2016

Creating Route Constraints using Attribute-based Routing in ASP.NET Web API

When you are writing your Web API methods, you may encounter a situation whereby you have two different methods that need to be distinguished from each other through their routes?

For example, if you have a method GetById(int id) and GetById(string id), how do you distinguish between these 2 routes when documenting your Web API using Attribute-based routing?

Well, through Route Constraints of course!

Therefore, you can then have Web API methods like the following:

No comments:

Post a Comment