A small microservices .NET core sample

A picture


Donny Bottse



Reading time

2 minutes

I would like to show you the creation of a simple REST Full Web API, while, at the same time, keeping our code as simple as possible. This in order to keep clarity, focus and understand the beginning concepts of microservices architecture. And nothing gets the job done better than having some working code for you to play around with.

I’ve created a small case study to give some guidelines of how we can approach this.

With that all said let’s dive in.

Case Study:

A fictional startup called Apep wants to create an app which organizes media files. A user needs to log in before making any changes and we also need to be able to manipulate media files.

Application Architecture

As I’ve already mentioned our back-end will be built following a micro services architecture.

Our back-end will contain the following:

  • Identity Microservice – Authenticates users based on username, password and issues a Bearer token which contains Claims-based identity information in it.
  • Media Microservice – Handles media uploads, deletions such as get, post, delete
  • API Gateway – Acts as a center point of entry to the back-end application, Provides data aggregation and communication path to microservices.
A picture

In our solution we have a couple of services. We will be discussing their purposes and how they execute them.

Media Service

Our media service is responsible for manipulating media pushed from a client. Right now, we only have photocontroller.

Identity Service

Our identity service is responsible for Authentication. Using username and password as input. When these are valid, it issues a JWT Bearer token with Claims-Identity info in it.


Validates incomings http requests by checking for the authorized JWT token in it. Our gateway will be our main entry point.


I will not be discussing the client who/that is included in the code since that is not the focus but feel free to go through it and use it as you please.

How to run the application:

  1. Clone or download the source code.
  2. Make sure you to replace the connection string with your own.
  3. Entityframeworkcore is being used for data access so before running it do an update on your database (dotnet ef database update )
  4. Make sure you run all the projects in the solution
  5. The sample user details are hard coded in the User Service.
  6. Use postman (figure 1.1) to retrieve the bearer token (figure 1.2).
  7. Use this bearer token to request data from the media service (figure 2.0). If all steps have been done correctly, access to the media service should be granted. Voilà, enjoy!

A picture
Figure 1.1
A picture
Figure 1.2
A picture
Figure 2.0

Blijf op de hoogte met Craft

Wil jij geen events meer missen en via blogs op de hoogte blijven van alle ontwikkelingen rondom .NET Development? Meld je dan aan voor de Craft-update!