How to use API Analyzers in ASP.NET Core

Maria J. Danford

API Analyzers, introduced with ASP.Web Core two.two, enable you to adhere to a established of conventions to make improvements to the documentation of the APIs of your ASP.Web Core apps. API Analyzers function with any controller that is adorned with the [ApiController] attribute. This post discusses how we can function […]

API Analyzers, introduced with ASP.Web Core two.two, enable you to adhere to a established of conventions to make improvements to the documentation of the APIs of your ASP.Web Core apps. API Analyzers function with any controller that is adorned with the [ApiController] attribute. This post discusses how we can function with API Analyzers in ASP.Web Core 3.1.

To function with the code illustrations supplied in this post, you need to have Visible Studio 2019 set up in your system. If you never presently have a duplicate, you can download Visible Studio 2019 below. 

Develop an ASP.Web Core 3.1 API undertaking

Initial off, let’s make an ASP.Web Core undertaking in Visible Studio. Assuming Visible Studio 2019 is set up in your system, adhere to the techniques outlined under to make a new ASP.Web Core undertaking in Visible Studio.

  1. Launch the Visible Studio IDE.
  2. Click on “Create new undertaking.”
  3. In the “Create new project” window, find “ASP.Web Core Net Application” from the checklist of templates exhibited.
  4. Click Future.
  5. In the “Configure your new project” window, specify the title and site for the new undertaking.
  6. Click Develop.
  7. In the “Create New ASP.Web Core Net Application” window proven subsequent, find .Web Core as the runtime and ASP.Web Core two.two (or later) from the drop-down checklist at the top rated. I’ll be making use of ASP.Web Core 3.1 below.
  8. Select “API” as the undertaking template to make a new ASP.Web Core API application.
  9. Guarantee that the test containers “Enable Docker Support” and “Configure for HTTPS” are unchecked as we won’t be making use of these options below.
  10. Guarantee that Authentication is established as “No Authentication” as we won’t be making use of authentication both.
  11. Click Develop.

This will make a new ASP.Web Core API undertaking in Visible Studio. Now find the Controllers resolution folder in the Alternative Explorer window and click “Add -> Controller…” to make a new controller named DefaultController. We’ll use this undertaking in the subsequent sections of this post.

Set up the API Analyzers NuGet package deal

If you are making use of with ASP.Web Core two.two, to function with API Analyzers in ASP.Web Core, you need to install the Microsoft.AspNetCore.Mvc.Api.Analyzers package deal from NuGet. You can do this both by using the NuGet Offer Manager inside the Visible Studio 2019 IDE, or by executing the next command in the NuGet Offer Manager Console:

Set up-Offer Microsoft.AspNetCore.Mvc.Api.Analyzers

Notice that you do not have to have to install the NuGet package deal if you are making use of ASP.Web Core 3. or increased mainly because the analyzers are included as part of the .Web Core 3.x SDK.

Develop the product and repository classes in ASP.Web Core

Select the Models folder of the undertaking we have just produced and make a product course as proven under.

    general public course Creator
   
        general public int Id get established
        general public string FirstName get established
        general public string LastName get established
   

We’ll also have to have a Repository course – a simple, minimalist implementation of a repository – we’re not connecting to the databases below. The AuthorRepository course is proven in the code snippet given under.

Copyright © 2020 IDG Communications, Inc.

Next Post

New Swift project handles server app startup, shutdown

The developers powering Apple’s Swift language have launched an open up source venture for the Swift server ecosystem, known as Swift Assistance Lifecycle, to help server purposes with controlling startup and shutdown sequences. Available from GitHub, Swift Assistance Lifecycle is a Swift package that cleanly commences up and shuts down an […]

Subscribe US Now