.NET Conf 2019
.NET Core 3.0 launches at .NET Conf 2019 September 23-25, a free, virtual developer event.

.NET Tutorial - Hello World Microservice

Create your service

Create an app

In your command prompt, run the following commands:

In your terminal, run the following commands:

Command prompt
dotnet new webapi -o myMicroservice --no-https
cd myMicroservice

The dotnet command creates a new application of type webapi (that's a REST API endpoint).

  • The -o parameter creates a directory named myMicroservice where your app is stored.
  • The --no-https flag creates an app that will run without an HTTPS certificate, to keep things simple for deployment.

The cd myMicroService command puts you into the newly created app directory.

The generated code

Several files were created in the myNewMicroService directory, to give you a simple service that is ready to run.

  • myMicroservice.csproj defines what libraries the project references etc.
  • Startup.cs contains all the settings and configuration that are loaded when the app starts.
  • Controllers/ValuesController.cs has code for a simple API that returns a list of values.
ValuesController.cs (shortened for clarity)
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    // GET api/values
    [HttpGet]
    public ActionResult<IEnumerable<string>> Get()
    {
        return new string[] { "value1", "value2" };
    }
}
Continue