Using Service Connectors with PostgreSQL Database
This tutorial takes you through setting up a .NET Core application with the PostgreSQL service connector.
Note
For more detailed examples, please refer to the PostgreSql project in the Steeltoe Samples Repository.
First, start a PostgreSQL instance using the Steeltoe dockerfile.
docker run --env POSTGRES_PASSWORD=Steeltoe789 --publish 5432:5432 steeltoeoss/postgresql
Next, create a .NET Core WebAPI that interacts with PostgreSQL
Create a new ASP.NET Core WebAPI app with the Steeltoe Initializr
Name the project "PostgreSqlConnector"
Add the "PostgreSQL" dependency
Click Generate to download a zip containing the new project
Extract the zipped project and open in your IDE of choice
Set the instance address in appsettings.json
{ "postgres": { "client": { "server": "127.0.0.1", "port": "5432", "username": "postgres", "password": "Steeltoe789" } } }
Tip
Looking for additional params to use when connecting? Have a look at the docs
Run the application
dotnet run <PATH_TO>\PostgreSqlConnector.csproj
Navigate to the endpoint (you may need to change the port number) http://localhost:5000/api/values
Once the app loads in the browser you will see a list of the default database schemas installed with PostgreSQL. "["UTF8","UTF8","UTF8"]"