banner



Deploy An App That Uses An Api?

Deploy an API app in Azure App Service

[AZURE.INCLUDE app-service-api-v2-note]

Overview

In this tutorial, you deploy the Web API project that you created in the previous tutorial to a new API app. You use Visual Studio to create the API app resource in Azure App Service and to deploy your Web API code to the Azure API app.

Other deployment options

There are many other ways to deploy API apps. An API app is a web app with extra features for hosting web services, and all of the deployment methods that are available for web apps can also be used with API apps. The web app that hosts an API app is called the API app host in the Azure preview portal, and you can configure deployment by using the API app host portal blade. For information about the API app host blade, see Manage an API app.

The fact that API apps are based on web apps also means that you can deploy code written for platforms other than ASP.NET to API apps. For an example that uses Git to deploy Node.js code to an API app, see Create a Node.js API app in Azure App Service.

Create the API app in Azure

In this section, you use the Visual Studio Publish Web wizard to create an API app in Azure. Where the instructions direct you to enter a name for the API app, enter ContactsList.

[AZURE.INCLUDE app-service-api-pub-web-create]

Deploy your code to the new Azure API app

You use the same Publish Web wizard to deploy your code to the new API app.

[AZURE.INCLUDE app-service-api-pub-web-deploy]

Call the Azure API app

Since you enabled the Swagger UI in the previous tutorial, you can use that to verify that the API app is running in Azure.

  1. In the Azure preview portal, go to the API app blade for the API app that you deployed.

  2. Click the API app's URL.

    Click the URL

    An "API app successfully created" page appears.

  3. Add "/swagger" to the end of the URL in the browser address bar.

  4. In the Swagger page that appears, click Contacts > Get > Try it Out.

    Try it out

View the API definition in the portal

  1. In the Azure preview portal, go back to the API app blade for the API app that you deployed.

  2. Click API Definition.

    The app's API Definition blade shows the list of API operations that you defined when you created the app.

    API Definition

Next, you'll make a change to the API definition and see the change reflected in the portal.

  1. Go back to the project in Visual Studio and add the following code to the ContactsController.cs file.

                                          [HttpPost]  public HttpResponseMessage Post([FromBody] Contact contact)  {  	// todo: save the contact somewhere  	return Request.CreateResponse(HttpStatusCode.Created);  }                                  

    This code adds a Post method that can be used to post new Contact instances to the API.

    The code for the Contacts class now looks like the following example.

                                          public class ContactsController : ApiController  {      [HttpGet]      public IEnumerable<Contact> Get()      {          return new Contact[]{                      new Contact { Id = 1, EmailAddress = "barney@contoso.com", Name = "Barney Poland"},                      new Contact { Id = 2, EmailAddress = "lacy@contoso.com", Name = "Lacy Barrera"},                      new Contact { Id = 3, EmailAddress = "lora@microsoft.com", Name = "Lora Riggs"}                  };      }        [HttpPost]      public HttpResponseMessage Post([FromBody] Contact contact)      {          // todo: save the contact somewhere          return Request.CreateResponse(HttpStatusCode.Created);      }  }                                  
  2. In Solution Explorer, right-click the project and select Publish.

  3. Click the Preview tab

  4. Click Start Preview to see which file(s) will be copied to Azure.

    Publish Web dialog

  5. Click Publish.

  6. Restart the gateway as you did the first time you published.

  7. Once the publish process has completed, go back to the portal, and close and reopen the API Definition blade. You will see the new API endpoint you just created and deployed directly into your Azure subscription.

    API Definition

Next steps

You've seen how the direct deployment capabilities in Visual Studio make it easy to test that your API works correctly. In the next tutorial, you'll see how to debug your API app while it runs in Azure.

API apps are web apps with extra features for hosting APIs, which means you can use any deployment method that works with web apps. For more information about deployment options for web apps, see Deploy a web app in Azure App Service.

For information about API Apps features, see What are API apps?.

Deploy An App That Uses An Api?

Source: https://github.com/Huachao/azure-content/blob/master/articles/app-service-api/app-service-dotnet-deploy-api-app.md

Posted by: tharpsandint.blogspot.com

0 Response to "Deploy An App That Uses An Api?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel