REST Web API using C# and ASP.NET Core
Configure project:
source configure.sh
Run:
./watch.sh
Browse the docs and test the API via the Swagger UI:
open http://localhost:5000/docs
Browse the docs using Redoc. This is an alternative to the Swagger UI:
open http://127.0.0.1:5000/redoc
Run unit tests:
dotnet test
If you want to use migrations
Add first migration and initialize the database:
dotnet ef --project swift-api migrations add InitialCreate
Create database:
dotnet ef --project swift-api database update
Point .env
to the new database:
echo 'DATABASE_URL=sqlite:///./swift-api/books.db' > .env
Run the application:
dotnet run
In order to do this you will need Podman. See Setup Podman on macOS for details.
Rebuild container image and start container:
./podman.sh
Delete container and image:
./podman-delete.sh
Activate dotnet
:
export DOTNET_ROOT=$HOME/.dotnet
export PATH="$HOME/.dotnet:$PATH"
dotnet new sln --name swift-api
# add web project
dotnet new web --name swift-api --framework net8.0
dotnet sln add swift-api
# add packages
dotnet add swift-api package DotNetEnv
dotnet add swift-api package Microsoft.EntityFrameworkCore
dotnet add swift-api package Microsoft.EntityFrameworkCore.Design
dotnet add swift-api package Microsoft.EntityFrameworkCore.Sqlite
dotnet add swift-api package Microsoft.AspNetCore.OpenApi
dotnet add swift-api package Swashbuckle.AspNetCore
# add test project
dotnet new xunit --name swift-api-tests
dotnet sln add swift-api-tests
dotnet add swift-api-tests package Microsoft.EntityFrameworkCore.InMemory
dotnet add swift-api-tests package Microsoft.AspNetCore.Mvc.Testing
# add reference to the main project
dotnet add swift-api-tests reference swift-api
# add tools
dotnet tool install --global dotnet-ef