This is a sample api using ASP.NET Core 3.1, CQRS with MediatR, Microsoft Sql Server or In Memory and a lot of fun things like swagger and JWT, following the principles of Clean Architecture.
- .NET Core 3.1
- Entity Framework Core 3.1
- MediatR
- AutoMapper
- FluentValidation
- Swagger
- xUnit, Moq, Expected Objects, Bogus
- Kibana, Elastic Search and Serilog
This solution is configured to use a Microsoft sql database by default.
If you would like to use In Memory, there is a key to be updated in WebApi/appsettings.{ENVIRONMENT}.json as follows:
"UseInMemoryDatabase": true,
(This ensures that all users will be able to run the solution without needing to set up additional infrastructure)
Verify that the DbConnection connection details within appsettings.{ENVIRONMENT}.json points to a valid SQL Server instance.
When you run the application the database will be automatically created (if necessary) and the latest migrations will be applied.
The easiest way to get started is to install Docker in your computer and:
- Navigate to root folder, same where sample-api.sln is located.
- Run the command
docker-compose run -d
<< this will setup the environment using Microsoft Sql Server - Run the command
docker-compose -f docker-compose-in-mem.yml up -d
<< this will setup the environment using in memory database
- Run the command
- Both docker-compose will use kibana and elastic search for loggin purpose (use the routes /, /error and /user/auth to test it)
- Docker compose will download all necessary components
- Navigate to http://localhost:8080/, you should receive a message like <<I'm on baby! - Current Environment: DockerInMem (or Docker)>>
- Wait until will be able to acess kibana on http://localhost:5601 (kind of 1 or 2 minutes)
- Click on Explore on my own (it might not show, just jump it to next step)
- Navigate to http://localhost:5601/app/kibana#/management/kibana/index_patterns and Create index pattern. Define your index name equals to logstash-*
- Configure your Time Filter Field Name as @timestamp and continue
- Just access http://localhost:8080 to check if it's working fine
- Use http://localhost:8080/error to add some error data into kibana
ps.: if you want to run locally, without docker, you must run docker-compose -f docker-compose-kibana.yml up -d
to configure both kibana and elastic search
You can check all API endpoints at http://localhost:8080/swagger. Thanks Swagger
There is a file simple-api.postman_collection.json containing all possible consuming api endpoint, with data, for using with Postman v7.24.0.
A initial user to authenticate is provider under the following credentials email: [email protected] and password: 123
Most of api endpoints requires a token authentication (supplied by http://localhost:5000/user/auth endpoint). Add this token in you header request (see postman file for more details).