.Net Core 3 - Part 1 - Swagger
Tags: netcore, swagger, visualstudio2019
Published: 2019-10-15 21:05:52

![titulo](https://thepracticaldev.s3.amazonaws.com/i/jkcwlqhr7vqobmv0kist.jpg)
In this series, I will explain how to create a .Net Core 3 web API connected with a database and deployed to a remote server. The first step is to integrate it with Swagger by using the Swashbuckle package.  
The full example can be downloaded in this GitHub repository: [NetCore3-Swagger](https://github.com/lucianopereira86/NetCore3-Swagger).
## Technologies
* [.Net Core 3](https://docs.microsoft.com/pt-br/dotnet/core/whats-new/dotnet-core-3-0)
* [Visual Studio 2019](https://visualstudio.microsoft.com/pt-br/vs/)
* [Swagger](https://docs.microsoft.com/pt-br/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.0&tabs=visual-studio)

## Topics
* [.Net Core 3](#net-core-3)
* [Swagger](#swagger)

### .Net Core 3
Download the Visual Studio 2019 [here](https://visualstudio.microsoft.com/pt-br/vs/) and install it.
Create a new project:

![netcore01](https://thepracticaldev.s3.amazonaws.com/i/uey8xj0jbgrvj29dxfdn.jpg)
Choose ASP.Net Core Web Application:
![netcore02](https://thepracticaldev.s3.amazonaws.com/i/he9vs1kat0er2d7piuqt.jpg)
Name the project and configure the local path:
![netcore03](https://thepracticaldev.s3.amazonaws.com/i/084yrzpb3b5n6qp1xykk.jpg)
Select an empty .Net Core project and uncheck the HTTPS and Docker support options:

![netcore04](https://thepracticaldev.s3.amazonaws.com/i/8kut8mpg2v4flz6ytlhm.jpg)

After the solution be compiled, create a folder named "Controllers" and add into it a class named "TestController" with an async method:

![netcore07](https://thepracticaldev.s3.amazonaws.com/i/bg40q2cgz3spgv8b95yq.jpg)

Now, let's configure the "Startup" class:

![netcore08](https://thepracticaldev.s3.amazonaws.com/i/p7cph3u8h0ud9a0dd9ne.jpg)

Run the project in debug mode and access the URL below:
```bash
http://localhost:<API-PORT>/api/Test
```
If the "OK!" message be displayed in the browser, our web API is running!
### Swagger
Inside the Visual Studio 2019, open the Package Manager Console and run the following commands to install the Swashbuckle version compatible with .Net Core 3:
```bash
Install-Package Swashbuckle.AspNetCore -Version 5.0.0-rc3
Install-Package Swashbuckle.AspNetCore.Filters -Version 5.0.0-rc3
Install-Package Swashbuckle.AspNetCore.Annotations -Version 5.0.0-rc3
```

Open the "Startup" class again and modify the "ConfigureServices" method:

![swagger01](https://thepracticaldev.s3.amazonaws.com/i/0105v91chclhdghedpc3.jpg)

And the "Configure" method as well:

![swagger02](https://thepracticaldev.s3.amazonaws.com/i/rt1huydncx5dhpd6m60r.jpg)

Open the project's properties window, go to "Debug" and type "swagger" inside the input field above the environment variables list:

![swagger04](https://thepracticaldev.s3.amazonaws.com/i/yz0lx3lh3u8vfp8c0xt7.jpg)

Inside the "TestController", put a simple annotation above the "Get" method:

![swagger03](https://thepracticaldev.s3.amazonaws.com/i/svurys2uk5o52hbtukb0.jpg)

Now, let's run the project again. The Swagger page will open in this URL:
```bash
http://localhost:<API-PORT>/swagger/index.html
```

This will be the result:
![swagger08](https://thepracticaldev.s3.amazonaws.com/i/f1kfik9gsxdcozccmbp0.jpg)
Try the "Get" method and the "OK!" message will return from the API.
![swagger09](https://thepracticaldev.s3.amazonaws.com/i/fvh2v76o43ri6e8t282d.jpg)
## Conclusion
In 10 minutes, you were able to create a .Net Core 3 web API with Swagger. In the next chapter, we will connect it with a remote MySQL database.