This repository contains a demo .NET 9 backend API that provides authentication and data synchronization endpoints for a PowerSync enabled application. It allows client devices to sync data with a PostgreSQL database.
-
GET
/api/auth/token
- PowerSync uses this endpoint to retrieve a JWT access token for authentication.
-
GET
/api/auth/keys
- PowerSync uses this endpoint to validate the JWT returned from the authentication endpoint.
-
PUT
/api/data
- PowerSync uses this endpoint to sync upsert events from the client application.
-
PATCH
/api/data
- PowerSync uses this endpoint to sync update events from the client application.
-
DELETE
/api/data
- PowerSync uses this endpoint to sync delete events from the client application.
-
POST
/api/data
- PowerSync uses this endpoint to sync upsert batched events from the client application.
- .NET 9 SDK
- PostgreSQL, MongoDB, or MySQL database
- PowerSync credentials
The application requires the following environment variables:
DATABASE_URI=<your_database_connection_string>
DATABASE_TYPE=<postgresql|mongodb|mysql>
POWERSYNC_PRIVATE_KEY=<your_private_key>
POWERSYNC_PUBLIC_KEY=<your_public_key>
POWERSYNC_URL=<your_powersync_url>
PORT=5000
JWT_ISSUER=<your_jwt_issuer>
git clone https://github.com/dean-journeyapps/powersync-dotnet-api-demo.git
cd powersync-dotnet-api-demo
-
Create a new
.env
file in the root project directory and add the variables as defined in the.env
filecp .env.template .env
-
Build the Docker image:
docker build -t powersync-dotnet .
-
Run the container:
docker run -p 5000:5000 --env-file .env powersync-dotnet
This will start the app on http://127.0.0.1:5000
.
- Restore dependencies:
dotnet restore
- Build the application:
dotnet build
- Run the application:
dotnet run --project PowerSync.Api
You can test if the API is running by opening:
http://127.0.0.1:5000/api/auth/token
You should receive a JSON response with an access token.
If you wish to contribute, please fork the repository and submit a pull request.
This project is licensed under the MIT License.