Skip to content

darlissonlimeira/superhero-api-dotnet-8

Repository files navigation

Superhero API CRUD

This project had as main goal learn more about docker, docker compose, communication between docker containers as well building APIs with .Net 8 and Entity Framework.

Techs

- Docker
- .NET 8
- Postgres
- Swagger   

How to run

Requirements:

- docker;
- docker-compose 3.8 or later;

First of all you need to open the project folder in bash!

Running the database container:

  • Run docker compose up -d superohero_db

Now we need to create the superheroes table in the "postgres" database:

  • Run docker exec -it superhero_db bash - to get inside the container;
  • Run psql -U postgres
  • Create superheroes table:
    CREATE TABLE superheroes (
        "Id" integer GENERATED BY DEFAULT AS IDENTITY,
        "Name" text NOT NULL,
        "FirstName" text NOT NULL,
        "LastName" text NOT NULL,
        "Place" text NOT NULL,
        CONSTRAINT "PK_superheroes" PRIMARY KEY ("Id")
    );
    

Running the API container:

Because we need to pass the url connection of our database as an environment variable, we have to first build our docker api image and then we run our api container.

  • Run docker compose build superhero_api - This command gonna create a image of your API without running it
  • Then run docker run --name superhero_api -p 127.0.0.1:8080:8080 -e ConnectionStrings__DBConnection="Host=superhe ro_db;Database=postgres;Username=postgres;Password=postgres;" --network=superhero_app -d superhero_api - This command gonna start our container. It setup the port and host, network name that has to be the same of our database container network, so the api container can communicate with our database.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published