Skip to content

ruirizzi/microservice-lab

Repository files navigation

microservice-lab

Lab repository to test microservices.

Why?

I've created this repo as a laboratory to test how I could develop a simple microservice composed of a WebApi, a WebServer and a Database. All inside a Docker container.

The chosen technologies where .NET Core as framework, nginx as reverse proxy and MSSQL Server Linux Docker image.

Docker was also used, obviously.

Getting Started

This small guide should help you run the Docker image and run tests.

Build the Code

This WebAPI was developed in ASPNet Core so in order to build, publish and run tests, you must have dotNet Core installed on your environment.

Check out their download page and follow the installation instructions for your system.

After installing, open a terminal window and enter dotnet --version to check if the installation was successful:

dotnet version command result

Clone this repo and then:

dotnet restore
dotnet build
dotnet publish

This will allow you to correctly build the WebAPI.

Runing the Docker Containers

In order to run the Docker image, you must have Docker installed in you Windows, Linux or Mac. After installing Docker on your system and certifying that it is running, you should:

~\microservice-lab\docker volume create sqlserverdata 
~\microservice-lab\docker-compose build
~\microservice-lab\docker-compose up

The result should look like this:

docker-compose up result

Building and publishing in a single step

Alternatively to the aforementioned building steps, you can simply run one of the scripts on the project's root folder.

Run the bash script build.sh

After that you can just docker-compose up

Using

Default Bank Accounts

By default, I've inserted 6 bank accounts to the database:

bank accounts

Transfer Funds

You can POST to localhost/api/bank a fund transfer request and the API will try to place it, if the bank accounts have funds and/or are allowed to go overdraft (negative funds). The body should be:

post body

If everything goes right, you should get a 200 OK status message.

If a given account number does not exists, you'll get a 404 Not Found status message.

If the origin account doesn't allow overdraft (negative funds), you'll get a 400 Bad Request status message.

Checking entries

You can check an account entries (transaction history) by GET to localhost/api/bank/GetEntriesByAccountId/{accountId}; so, regarding the transfer mentioned above, making this request to the AccountId 2, will return:

And for the AccountId 1:

License

badge

About

Test Microservice repository.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages