Skip to content

dirocchini/sample-api

Repository files navigation

Sample Api

.NET Core Build Status Quality Gate Status


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.

Technologies

  • .NET Core 3.1
  • Entity Framework Core 3.1
  • MediatR
  • AutoMapper
  • FluentValidation
  • Swagger
  • xUnit, Moq, Expected Objects, Bogus
  • Kibana, Elastic Search and Serilog

Database Configuration

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.

Getting Started!

The easiest way to get started is to install Docker in your computer and:

  1. 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
  2. Both docker-compose will use kibana and elastic search for loggin purpose (use the routes /, /error and /user/auth to test it)
  3. Docker compose will download all necessary components
  4. Navigate to http://localhost:8080/, you should receive a message like <<I'm on baby! - Current Environment: DockerInMem (or Docker)>>
  5. Wait until will be able to acess kibana on http://localhost:5601 (kind of 1 or 2 minutes)
  6. Click on Explore on my own (it might not show, just jump it to next step)
  7. Navigate to http://localhost:5601/app/kibana#/management/kibana/index_patterns and Create index pattern. Define your index name equals to logstash-*
  8. Configure your Time Filter Field Name as @timestamp and continue
  9. Just access http://localhost:8080 to check if it's working fine
  10. 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

Testing

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: admin@domain.com 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).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published