Project in dotnet 6 using EntityFrameworkCore, Postgre, Container. Everything made in VSCode using a Linux OS machine.
Fist, you're going to install dotnet in your machine.
This command is for a Arch Linux machine. You can found the steps for you OS here: https://dotnet.microsoft.com/en-us/download
sudo pacman -S dotnet-sdk aspnet-runtimeNow create PostgesSQL service. I decided to create it using a container.
docker run --name postgres -e POSTGRES_PASSWORD=root -p 5432:5432 -d postgresConnect in your PostgresSQL and create the database dotnet.
CREATE DATABASE dotnetThen add some tool to handle EntityFramework to your database.
dotnet tool install --global dotnet-efInside the project cloned in your machine.
dotnet ef migrations add Initial --context PostgresContextdotnet ef database update --context PostgresContextMake sure that you have dotnet 6 installed in your machine.
dotnet runIn order for the dotnet container communicate with Postgres container, you must change the DefaultConnection present in appsettings.json with your local machine's IP.
{
"ConnectionStrings": {
"DefaultConnection": "Server=YOU_IP_HERE;Port=5432;Database=dotnet;User Id=postgres;Password=root;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}Build image.
docker build -t dotnet-six -f Containerfile .Create container.
docker run --name dotnet-six -p 8000:80 dotnet-sixYou can go to https://projecturl:port/swagger and test everything there!
Add a user.
curl -X 'POST' 'https://localhost:7206/api/User' -H 'accept: text/plain' -H 'Content-Type: application/json' -d '{ "name": "Name", "email": "mail@mail.com" }'Return all users.
curl -X 'GET' 'https://localhost:7206/api/User' -H 'accept: text/plain'Get user by id.
curl -X 'GET' 'https://localhost:7206/api/User/6dc55597-c935-4a6a-ba5c-cd57035cf43d' -H 'accept: text/plain' Update user by id.
curl -X 'PUT' 'https://localhost:7206/api/User/6dc55597-c935-4a6a-ba5c-cd57035cf43d' -H 'accept: */*' -H 'Content-Type: application/json' -d '{ "name": "User", "email": "mail@mail.com" }'Delete user by id.
curl -X 'DELETE' 'https://localhost:7206/api/User/6dc55597-c935-4a6a-ba5c-cd57035cf43d' -H 'accept: */*'