Creating microservice using .NET core
Today, I want to share how to create microservice using Microsoft .NET core.
What is Microservice?
“Microservice” is a new term on the crowded streets of software architecture, A microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
The only pre-requisites to start creating microservice are
- Visual Studio Code, You can download it here
- .NET Core SDK, You can download it here
- Check installed .NET Core version on your machine, type the below command in your terminal
dotnet — version
Create a sample microservice
- Open your terminal and run the below command.
dotnet new webapi — name sample-microservice
You will get the below result of the above execution.
2. Open your Visual Studio Code editor
3. Go to File -> Open Folder (Select your application folder)
Now you will be able to see the project structure
4. Now you are going to build and run your sample-microservice using the below commands in your terminal
cd sample-microservice
dotnet build
The output looks like below.
5. Run your sample-microservice application
dotnet run
The output looks like below.
Your application is running and you can check using this URL https://localhost:5001/WeatherForecast