Sier.WebAPI.Boilerplate 0.1.13

There is a newer version of this package available.
See the version list below for details.
dotnet new install Sier.WebAPI.Boilerplate::0.1.13                
This package contains a .NET Template Package you can call from the shell/command line.

I created a modification of the FullStackHero Boilerplate, an open-source project, by adding additional functionality to suit my specific needs. Before making a formal pull request (PR) to the original FullStackHero repository on GitHub, I preferred to thoroughly test my modifications to ensure their effectiveness and compatibility.

What's fullstackhero's .NET Web API Boilerplate?

fullstackhero's .NET Web API Boilerplate is a starting point for your next .NET 7 Clean Architecture Project that incorporates the most essential packages and features your projects will ever need including out of the box Multi-Tenancy support. This project can save well over 200+ hours of development time for your team.

As the name suggests, this is an API / Server Boilerplate. You can find other Client Boilerplates that consume this API under @fullstackhero handle.

YouTube Video - .NET Web API Boilerplate | FullStackHero - Getting Started

Watch the Getting started video here : https://www.youtube.com/watch?v=a1mWRLQf9hY

.NET Web API Boilerplate | FullStackHero - Getting Started

Goals

The goal of this repository is to provide a complete and feature-rich starting point for any .NET Developer / Team to kick-start their next major project using .NET 7 Web API. This also serves the purpose of learning advanced concepts and implementations such as Multitenancy, CQRS, Onion Architecture, Clean Coding standards, Cloud Deployments with Terraform to AWS, Docker Concepts, CICD Pipelines & Workflows and so on.

Features

  • Built on .NET 7.0
  • Follows Clean Architecture Principles
  • Domain Driven Design
  • Cloud Ready. Can be deployed to AWS Infrastructure as ECS Containers using Terraform!
  • Docker-Compose File Examples
  • Documented at fullstackhero.net
  • Multi Tenancy Support with Finbuckle
    • Create Tenants with Multi Database / Shared Database Support
    • Activate / Deactivate Tenants on Demand
    • Upgrade Subscription of Tenants - Add More Validity Months to each tenant!
  • Supports MySQL, MSSQL, Oracle & PostgreSQL!

<details> <summary>Click to See More!</summary>

  • Uses Entity Framework Core as DB Abstraction
  • Flexible Repository Pattern
  • Dapper Integration for Optimal Performance
  • Serilog Integration with various Sinks - File, SEQ, Kibana
  • OpenAPI - Supports Client Service Generation
  • Mapster Integration for Quicker Mapping
  • API Versioning
  • Response Caching - Distributed Caching + REDIS
  • Fluent Validations
  • Audit Logging
  • Advanced User & Role Based Permission Management
  • Code Analysis & StyleCop Integration with Rulesets
  • JSON Based Localization with Caching
  • File Storage Service
  • Test Projects
  • JWT & Azure AD Authentication
  • MediatR - CQRS
  • SignalR Notifications
  • & Much More </details>

Documentation

Read Documentation related to this Boilerplate here - https://fullstackhero.net/dotnet-webapi-boilerplate/

Feel free to contribute to the Documentation Repository - https://github.com/fullstackhero/docs

Getting Started

To get started with this Boilerplate, here are the available options.

  • Install using the FSH CLI tool. Use this for release versions of the Boilerplate only.
  • Fork the Repository. Use this if you want to always keep your version of the Boilerplate up-to date with the latest changes.

Make sure that your DEV enviroment is setup, Read the Development Environment Guide

FSH CLI Tool

Prerequisites

Before creating your first fullstackhero solution, you should ensure that your local machine has:

  • .NET 7 You can find the download here.
  • NodeJS (16+) You can find the download here.
Installation

After you have installed .NET, you will need to install the fsh console tool.

dotnet tool install --global FSH.CLI
fsh install

This isntall the FSH CLI tools and the associated Templates. You are now ready to create your first FSH project!

FSH .NET WebAPI Boilerplate

Here's how you would create a Solution using the FSH .NET WebAPI Boilerplate.

Simply navigate to a new directory (wherever you want to place your new solution), and open up Command Prompt at the opened directory.

Run the following command. Note that, in this demonstration, I am naming my new solution as FSH.Starter.

fsh api new FSH.Starter

OR

fsh api n FSH.Starter

This will create a new .NET 7 WEBAPI solution for you using the FSH Templates. For further steps and details, Read the Getting Started Guide

Update

To update the tool & templates, run the following commands

dotnet tool update FSH.CLI --global
fsh update

Forking the Repository

You would probably need to take this approach if you want to keep your source code upto date with the latest changes. To get started based on this repository, you need to get a copy locally. You have three options: fork, clone, or download.

  • Make a fork of this repository in your Github account.
  • Create your new dotnet-webapi-boilerplate personal project by cloning the forked repository on your personal github.
  • Setup an upstream remote on your personal project pointing to your forked repository using command git remote add upstream https://github.com/{githubuseraccount}/dotnet-webapi-boilerplate and git remote set-url --push upstream DISABLE

For step by step instructions, follow this and this.

Quick Start Guide

So, for a better developer experience, I have added Makefile into the solution. Now that our solution is generated, let's navigate to the root folder of the solution and open up a command terminal.

To build the solution,

make build

By default, the solution is configured to work with postgresql database (mainly because of hte OS licensing). So, you will have to make sure that postgresql database instance is up and running on your machine. You can modify the connection string to include your username and password. Connections strings can be found at src/Host/Configurations/database.json. Once that's done, let's start up the API server.

make start

That's it, the application would connect to the defined postgresql database and start creating tables, and seed required data.

For testing this API, we have 3 options.

  1. Swagger @ localhost:5001/swagger
  2. Postman collections are available ./postman
  3. ThunderClient for VSCode. This is my personal favorite. You will have to install the Thunderclient extension for VSCode.

The default credentials to this API is:

{
    "email":"admin@root.com",
    "password":"123Pa$$word!"
}

Open up Postman, Thunderclient or Swagger.

identity → get-token

This is a POST Request. Here the body of the request will be the JSON (credentials) I specified earlier. And also, remember to pass the tenant id in the header of the request. The default tenant id is root.

Here is a sample CURL command for getting the tokens.

curl -X POST \
  'https://localhost:5001/api/tokens' \
  --header 'Accept: */*' \
  --header 'tenant: root' \
  --header 'Accept-Language: en-US' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "email": "admin@root.com",
  "password": "123Pa$$word!"
}'

And here is the response.

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjM0YTY4ZjQyLWE0ZDgtNDNlMy1hNzE3LTI1OTczZjZmZTJjNyIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2VtYWlsYWRkcmVzcyI6ImFkbWluQHJvb3QuY29tIiwiZnVsbE5hbWUiOiJyb290IEFkbWluIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZSI6InJvb3QiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zdXJuYW1lIjoiQWRtaW4iLCJpcEFkZHJlc3MiOiIxMjcuMC4wLjEiLCJ0ZW5hbnQiOiJyb290IiwiaW1hZ2VfdXJsIjoiIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbW9iaWxlcGhvbmUiOiIiLCJleHAiOjE2ODA5NDE3MzN9.VYNaNvk2T4YDvQ3wriXgk2W_Vy9zyEEhjveNauNAeJY",
  "refreshToken": "pyxO30zJK8KelpEXF0vPfbSbjntdlbbnxrZAlUFXfyE=",
  "refreshTokenExpiryTime": "2023-04-15T07:15:33.5187598Z"
}

You will need to pass the token in the request headers to authenticate calls to the fullstackhero API!

For further steps and details, Read the Getting Started Guide

Containerization

The API project, being .NET 7, it is configured to have built-in support for containerization. That means, you really don't need a Dockerfile to containerize the webapi.

To build a docker image, all you have to do is, ensure that docker-desktop or docker instance is running. And run the following command at the root of the solution.

make publish

You can also push the docker image directly to dockerhub or any supported registry by using the following command.

make publish-to-hub

You will have to update your docker registry / repo url in the Makefile though!.

Docker Compose

This project also comes with examples of docker compose files, where you can spin up the webapi and database isntance in your local containers with the following commands.

make dcu #docker compose up - Boots up the webapi & postgresql container
make dcd #docker compose down - Shuts down the webapi & postgresql containers

There are also examples for mysql & mssql variations of the fsh webapi. You can find the other docker-compose files under the ./docker-compose folder. Read more about fullstackhero's docker-compose instructions & files here

Cloud Deployment with Terraform + AWS ECS

This is something you wont get to see very often with boilerplates. But, we do support cloud deployment to AWS using terraform. The terraform files are available at the ./terraform folder.

Prerequisites

  • Install Terraform
  • Install & Configure AWS CLI profiles to allow terraform to provision resources for you. I have made a video about AWS Credentials Management.

In brief, the terraform folder has 2 sub-folders.

  • backend
  • environments/staging

The Backend folder is internally used by Terraform for state management and locking. There is a one-time setup you have to do against this folder. Navigate to the backend folder and run the command.

terraform init
terraform apply -auto-approve

This would create the required S3 Buckets and DDB table for you.

Next is the environments/staging folder. Here too, run the following command.

terraform init

Once done, you can go the terraform.tfvars file to change the variables like,

  • project tags
  • docker image name
  • ecs cluster name and so on.

After that, simply back to the root of the solution and run the following command.

make ta

This will evaluate your terraform files and create a provision plan for you. Once you are ok, type in yes and the tool will start to deploy your .NET WebAPI project as containers along with a RDS PostgreSQL intance. You will be receiving the hosted api url once the provisioning is completed!

To destroy the deployed resources, run the following

make td

Overview - Read

Getting Started - Read

Development Environment - Learn about setting up the DEV environment

Participate in Discussions - QNA & General Discussions

Join our Discord - fullstackhero @ Discord

Changelogs

View Complete Changelogs.

Community

License

This project is licensed with the MIT license.

Support ⭐

Has this Project helped you learn something New? or Helped you at work? Here are a few ways by which you can support.

buy-me-a-coffee

Code Contributors

This project exists thanks to all the people who contribute. Submit your PR and join the elite list!

fsh dotnet webapi contributors

Financial Contributors

Become a financial contributor and help me sustain the project. Support the Project!

<a href="https://opencollective.com/fullstackhero"><img src="https://opencollective.com/fullstackhero/individuals.svg?width=890"></a>

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.21 690 7/6/2023
0.1.20 140 7/6/2023
0.1.19 188 7/3/2023
0.1.18 170 7/3/2023
0.1.17 175 7/3/2023
0.1.16 180 7/2/2023
0.1.15 153 7/2/2023
0.1.14 181 7/2/2023
0.1.13 167 7/2/2023
0.1.12 164 6/30/2023
0.1.11 166 6/20/2023
0.1.10 160 6/20/2023
0.1.9 148 6/16/2023
0.1.8 153 6/15/2023
0.1.7 165 6/15/2023
0.1.6 172 6/15/2023
0.1.5 611 6/14/2023
0.1.4 508 6/13/2023
0.1.3 284 6/13/2023
0.1.2 210 6/13/2023
0.1.1 164 6/12/2023
0.1.0 143 6/12/2023