1
votes

I have created Web API and deployed to Azure using VS. The API is published/hosted inside that Web App. I want to import that API (Web App) into APIM but I am only seeing the option to choose are

  1. 'Logic App'
  2. 'API App' and
  3. 'Function App'

There is nothing for Web App. Can we import that Web App into APIM?

2

2 Answers

0
votes

NO. Directly you can't. But get the url and configure by choosing blank API option or modify the code and get the Swagger file & import it.

0
votes

STEP 1- ADDING SWAGGER (OPEN API INTERFACE) The first step is to add swagger which is an open API interface and the it could be imported in API management. In order to add swagger first we must install a NuGet package in our existing applications.

STEP 2- EDITING STARTUP CLASS TO ACCOMMIDATE SWAGGER IN OUR APPLICATION Navigate to the Startup.cs or your Startup class if you have customized that to a different name and change the ConfigureServices and Configure methods to add Swagger to your WebAPI App as the below two methods.

Configure services:

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

    // Register the Swagger generator, defining 1 or more Swagger documents             
    services.AddSwaggerGen(c => 



    {                 
        c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });             
        }); 

    // Register the Swagger generator, defining 1 or more Swagger documents             
    services.AddSwaggerGen(c =>             
    {                 
        c.SwaggerDoc("MyApi", new Info                 
        {                     
            Version = "v1",                     
            Title = "My API",                    
             Description = "A simple example ASP.NET Core Web API",                     
             TermsOfService = "None",                     
             Contact = new Contact                     
             {                         
                 Name = "mfouad",                        
                  Email = string.Empty,                        
                   Url = ""                     
                   },                    
                    License = new License                    
                     {                         
                         Name = "Use under LICX",                        
                          Url = "https://example.com/license"                     
                          }                
                           });            
                            }); 
} 

And Configure:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)         
        {             
            if (env.IsDevelopment())             
            {                 
                app.UseDeveloperExceptionPage();             
                }             
                else            
                 {                 
                     app.UseHsts();            
                      } 

            // Enable middleware to serve generated Swagger as a JSON endpoint.             
            app.UseSwagger(); 

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),             
             // specifying the Swagger JSON endpoint.             
             app.UseSwaggerUI(c =>             
             {                 
                 c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");             
                 }); 


                app.UseHttpsRedirection(); 
                app.UseMvc(); 
        }

STEP 3- PUBLISH THESE CHANGES IN THE AZURE APP SERVICE

  1. Right click the project and select publish to add the new changes to the App service.

  2. Select and existing or create a new App service if there is no App Service existing

  3. Publish that to the App Service.

  4. Once published ensure that http://{ YourAppServiceName }.azurewebsites.net/swagger loading the API interface page

  5. Navigate to https://{YourAppServiceName}.azurewebsites.net/swagger/v1/swagger.json

STEP 4- ADD THE APIS TO API MANAGEMENT

  1. Navigate to the API Management resource in Azure
  2. Select from the left-hand pane APIs
  3. Click on OpenAPI
  4. You will be presented with a form to fill you can either download the json file to your local machine and validate it using swagger editor tool if there is any problems importing that file it can give you suggestions on items to fix before uploading that.
  5. Add the Swagger.json endpoint or file in the following form and click create.
  6. Add your API Endpoint to API Management click on the settings from the ribbon and add your app service URL in the web service URL field as the below image.
  7. Test your APIs in API Management by clicking on the Test from the ribbon and choose one of the APIs to send an example request to as per the below image.