Difference between Web API and Azure API APP in Visual Studio
Asked Answered
C

3

5

When creating an new ASP.NET Web application in order to develop my APIs and host it in Azure, I have two choices:

  • Web API
  • Azure API APP

I can create a Web API APP and host it in Azure API APP? So what's the main reason they both exist?

enter image description here

Capture answered 14/12, 2017 at 17:41 Comment(0)
G
4

They are just different starting points, depending on your needs.

Azure API is a stripped-down API-only template with OpenAPI support.

ASP.NET Web API is a full ASP.NET MVC app that is geared heavily towards supporting an API.

Difference #1: Authentication support in the Web API template

ASP.NET Web API

Supports authentication selection (None, Individual Users, Work or School, Windows). Screenshot showing selection of authentication support

ASP.NET Azure API App

Expects clients to present tokens (bearer tokens or API tokens). Configure authentication and authorization of users (not API tokens) using the Azure Portal. Use Azure API Management (or other services) to manage API tokens. Screenshot showing unavailable selector for authentication support

Difference #2: MVC support in Web API template

ASP.NET Web API

Automatically includes MVC in order to show Help pages. These are not the same as OpenAPI (Swagger) self-generated documentation. Screenshot showing MVC option preselected, non-editable

ASP.NET Azure API App

Doesn't automatically include MVC or Help pages Screenshot showing MVC option not selected, editable

Difference #3: Supporting files for UI in Web API

ASP.NET Web API

Includes Areas, Content, HomeController, fonts, Scripts, and Views Screenshot showing Solution Explorer with expanded assets

ASP.NET Azure API App

Screenshot showing Solution Explorer with minimal assets

Difference #4: More startup configuration in Web API template

ASP.NET Web API

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
}

ASP.NET Azure API App

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }
}

Difference #5: OpenAPI (Swagger) support in Azure API template

ASP.NET Web API

public class ValuesController : ApiController
{
    // GET api/values
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    public string Get(int id)
    {
        return "value";
    }

    // POST api/values
    public void Post([FromBody]string value)
    {
    }

    // PUT api/values/5
    public void Put(int id, [FromBody]string value)
    {
    }

    // DELETE api/values/5
    public void Delete(int id)
    {
    }
}

ASP.NET Azure API App

OpenAPI (Swagger) is enabled by default. The OpenAPI JSON document is at /swagger/docs/v1

public class ValuesController : ApiController
{
    // GET api/values
    [SwaggerOperation("GetAll")]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    [SwaggerOperation("GetById")]
    [SwaggerResponse(HttpStatusCode.OK)]
    [SwaggerResponse(HttpStatusCode.NotFound)]
    public string Get(int id)
    {
        return "value";
    }

    // POST api/values
    [SwaggerOperation("Create")]
    [SwaggerResponse(HttpStatusCode.Created)]
    public void Post([FromBody]string value)
    {
    }

    // PUT api/values/5
    [SwaggerOperation("Update")]
    [SwaggerResponse(HttpStatusCode.OK)]
    [SwaggerResponse(HttpStatusCode.NotFound)]
    public void Put(int id, [FromBody]string value)
    {
    }

    // DELETE api/values/5
    [SwaggerOperation("Delete")]
    [SwaggerResponse(HttpStatusCode.OK)]
    [SwaggerResponse(HttpStatusCode.NotFound)]
    public void Delete(int id)
    {
    }
}
Groggery answered 25/1, 2019 at 23:4 Comment(0)
I
2

You could check this link.

API apps in Azure App Service offer features that make it easier to develop, host, and consume APIs in the cloud and on-premises. With API apps you get enterprise grade security, simple access control, hybrid connectivity, automatic SDK generation


Web Apps is the compute resources that Azure provides for hosting a website or web application in App Service.The compute resources may be on shared or dedicated virtual machines (VMs), depending on the pricing tier that you choose. Your application code runs in a managed VM that is isolated from other customers.

Indonesia answered 15/12, 2017 at 2:5 Comment(2)
I am asking about the difference between the two templates in Visual Studio (web Api and azure api I didn't mention Web APPs). According to Azure API Apps and Web Apps, I believe they are the same and offer the same capabilities, the only one difference between them is the icon.Capture
@Coding In fact, Azure API apps is a kind of web app.Indonesia
R
1

Web API - This boiler plate will generate the template for MVC(Model/View/Control) pattern(Web App) and Web API in same solution.

Azure API App - This boiler plate will generate the template for Web API excluding related file for web app. and it has a one extra config file called SwaggerConfig.cs under app_start.
See here: ASP.NET Core Web API help pages with Swagger / Open API. It can be helpful when you publish the API into azure.

Rondel answered 9/6, 2018 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.