Example project for a minimal WebAPI with SQLite database backend. Contains all common tasks in a very condensed form.
Based on the following, simple data model:
@startuml hide empty methods enum ProductTypes { Food Drink } entity Product { Id: int Name: string Type: ProductTypes Price: decimal Hot: bool Vegetarian: bool Ingredients: List<Ingredient> } entity Menu { MenuNo: byte Date: DateOnly Products: List<MenuItem> } class Ingredient { Description: string Allergens: List<string> } entity MenuItem { Amount: short } ProductTypes "1" -r- "n" Product Product "m" -r- "n" Menu Product *-u- "n" Ingredient (Product, Menu) .. MenuItem @enduml
If you want to create the SQLite database in your dev environment first make sure you have the EF tools installed (dotnet tool install --global dotnet-ef
).
Then run dotnet ef database update
to apply the migrations contained in the project.
Note
|
The application will (re)create the database automatically when started, so this step is only required if you want to inspect the sample data while the application is not running. |
-
If you start the application from Rider it will automatically open a browser at the Swagger UI page
-
If you start it using
dotnet run
navigate to http://localhost:5001/swagger/index.html
For deployment to the server execute
dotnet publish -c Release -r linux-x64 --self-contained true
Note
|
If testing on Windows use RID win-x64
|
Allow the executable to be executed with:
chmod +x MinmalBackend
Then execute with
./MinmalBackend
-
In production the backend is available at port 5000!
-
e.g. Swagger at http://localhost:5000/swagger/index.html
-