0

I created an ASP.NET MVC application. I'm trying to expose functions as a REST API. I know it is probably better using asp. Net WEB API.

My question is can I add web api to my existing mvc application or do I have to completely create new web api project.

Or can both be functional in one project ?

1 Answer 1

0

You can add Web API to your existing Asp MVC project.

Add via nuget:
* Microsoft ASP.NET Web API 2.2

Also, ensure you have a WebAPIConfig class in your App_Start with the following:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.