Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Web API and Azure API APP in Visual Studio

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

like image 526
Hussein Salman Avatar asked Dec 14 '17 17:12

Hussein Salman


3 Answers

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)
    {
    }
}
like image 54
Alan McBee Avatar answered Sep 22 '22 21:09

Alan McBee


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.

like image 21
Shui shengbao Avatar answered Sep 22 '22 21:09

Shui shengbao


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.

like image 32
Hasiya Avatar answered Sep 23 '22 21:09

Hasiya