When creating an new ASP.NET Web application in order to develop my APIs and host it in Azure, I have two choices:
I can create a Web API APP and host it in Azure API APP? So what's the main reason they both exist?
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.
Supports authentication selection (None, Individual Users, Work or School, Windows).
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.
Automatically includes MVC in order to show Help pages. These are not the same as OpenAPI (Swagger) self-generated documentation.
Doesn't automatically include MVC or Help pages
Includes Areas, Content, HomeController, fonts, Scripts, and Views
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);
}
}
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
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)
{
}
}
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)
{
}
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With