An awesome boilerplate for your next .NET 6.0 based API. Its only goal is to simply kick-start your API development and provide you with some of the best practices when building amazing and scalable REST APIs 🔥
We baked in all the best REST API practices in terms of structuring your API, naming conversations, HTTP methods, responses, and optimizations
We all like to learn by examples and that's why the boilerplate comes with a concrete example that includes everything from folder structure, and routes to naming controllers
Building a versioning system that scales is always hard and that's why we included a robust versioning system that is easy to use and can grow with the project
The boilerplate uses the new .NET 6.0 Minimal APIs architecture.
The boilerplate is loosely based on Clean Architecture patterns without being too strict. The endpoints are kept 'thin' by using the Mediator Pattern with Mediatr.
Entity Framework Core is already included and we built two tables Users and Posts and defined everything you might need on a database and model level. You can easily expand the database by using the Entity Framework Migration system.
Built-in .NET Core Identity authentication using JWT Bearer tokens included in the boilerplate.
The boilerplate uses FluentValidation for consistent and scalable validation.
The boilerplate includes an example of a global exception handler which makes sure that the API always returns a user-friendly error message.
We added an awesome NuGet package called Treblle. Out of the box, Treblle gives you: real-time API monitoring, automatically generated and updated documentation, error tracking and logging, API analytics, quality scoring, and much more. To get started with Treblle visit treblle.com.
The Core project contains the domain and business logic. This is where the entity models and everything needed to interact with them is defined. The interfaces for repositories are defined here but it's left to the Infrastructure layer to implement them.
The Infrastructure project handles the communication with the database. It contains the implementations of the repositories defined in the Core project.
The Presentation project implements the Minimal API and contains everything that's needed to facilitate communication with the consumer. API endpoints are defined here and user actions are mapped to queries and commands which are sent to the Core layer using the Mediator Pattern.
- Entity Framework Core
- ASP.NET Core Identity
- Treblle for .NET Core
- Seriog
- Swashbuckle
- Mediatr
- AutoMapper
You can install this template using the dotnet new CLI. To install the latest version of the template run the following command:
dotnet new --install TreblleDotNetApiBoilerplate.Template
To create a new solution based on this template use this command:
dotnet new treblle_dotnet_api_boilerplate --name {YOUR_SOLUTION_NAMESPACE}
Optionally, you can also specify these parameters:
-c | --connectionString (Your database connection string)
-j | --jwtKey (Your JWT secret key)
-t | --treblleApiKey (Your Treblle API Key)
-tr | --treblleProjectId (Your Treblle Project Id)
Create a FREE account on https://treblle.com to get an API key and Project ID.
Once you have your Treble API Key and Project ID you'll have to copy them into app.config
. Alternatively, you can pass --treblleApiKey
and --treblleProjectId
parameters when creating a solution from the template.
The template was built for use with the Microsoft SQL Server database, but it can easily be modified for any other database provider.
Make sure to edit the connection string in appsettings.json
.
Warning: Change the default secret key for JWT token generation, as well as Issuer and Audience in appsettings.json
before using this boilerplate for production apps.
If you have problems of any kind feel free to reach out via https://treblle.com or email vedran@treblle.com, and we'll do our best to help you out.
Copyright 2022, Treblle Limited. Licensed under the MIT license: https://opensource.org/licenses/MIT