Asp.NET Web Api - multiple apis/namespaces

Question

In my MVC4 web app, I need to support multiple APIs. I looked around and apparently in Web API, Controllers with same name in different name spaces is not supported.

What are my options?

Ex: I want to be able to provide to my API consumers links like,

http://domainurl/api/api1/Students...
http://domainurl/api/api2/Students...

A Student Resource in api1 can be totally different from the one in api2. In such cases what is the best approach? I do not want to make it a single api and handle it through url parameters.

Solution

Maybe it might be better to seperate the 2 different APIs in to two different projects and have them worry about their own Apis.

  • MyApi.V1.csproj
  • MyApi.V2.csproj

Then have IIS point to the seperate versions using a virtual application

I think this is more manageable than smashing them into the same project file. Plus this will help each project out with reflection if you decide to use any resolvers.