Skip to content

API Setup

Henri Vainio edited this page Apr 14, 2025 · 1 revision

Development setup

Building and running LarpakeServer

1. Create local dev database

Complete all actions under title Development setup -> Dev database and migrations. You will download required development tools, create connection string and create all database tables in your postgres database server.

Configure repository

  1. Clone repository
git clone https://github.com/henrivain/Larpake.git
  1. Go to folder LarpakeServer/

  2. Create file LarpakeServer/appsettings.Development.json

  3. Fill file with following values

Note that your connection string ConnectionStrings.PostgreSQL might look different if you created it differently from database setup intructions.

{
  "ConnectionStrings": {
    "PostgreSQL": "Host=localhost; Port=5432; Database=larpake; Username=dev;Password=dev"
  },
  "Jwt": {
    "Issuer": "https://id.larpake.luuppi.fi",
    "Audience": "https://larpake.luuppi.fi",
    "SecretKey": "ThisIsSecretDevelopmentKeyTheReleaseKeyShouldNotBeHere",
    "RefreshTokenByteLength": 64,
    "AccessTokenLifetimeMinutes": 60,
    "RefreshTokenLifetimeDays": 30
  }
}

Run

  1. Open terminal in LarpakeServer -folder and run command
dotnet run build --launch-profile https
  1. View openapi page

Server launches and should open in port 7267. You can now view and make requests in openapi page https://localhost:7267/openapi.

Other things

image

Calling the Api requires JWT bearer token, which can be retrieved from endpoint /api/login with a user id. After getting you JWT token, you can paste you access token in the authentication field (image above). If you do not have user id yet, you can create one (for development purposes) in /api/sign-up endpoint. (Note: created user doesn't have any permissions so you must promote permissions directly in database, if you cannot figure it out, open a new issue!)


Dev database and migrations

Note that this tutorial only creates one do-all connection string that is fine for development, but for production, follow instructions in Database Administration wiki

1. Download tools

Download and install postgres: https://www.postgresql.org/download/windows/

Download and install .NET 9 sdk: https://dotnet.microsoft.com/en-us/download

2. Set environment variables

Add postgres to environment PATH variables, default path is "C:\Program Files\PostgreSQL\17\bin" image

3. Create connection string

i) Open postgres client in cmd:

psql -h localhost -d postgres -U postgres

ii) Give default password "postgres"

iii) Create user:

CREATE USER dev WITH PASSWORD 'dev';

iv) Create database:

CREATE DATABASE larpake;

v) Open the database:

\c larpake

vi) Give permissions to created user (do this in dev only):

GRANT ALL ON schema public TO dev;

vii) Now we have following connection string (Don't run this)

Host=localhost; Port=5432; Database=larpake; Username=dev;Password=dev

Configure migrations

Clone git repo

git clone https://github.com/henrivain/Larpake.git

Change branch

git checkout postgres

Open MigrationsService project and create file MigrationsService\appsettings.Development.json.

Paste configuration

{
  "ConnectionStrings": {
    "Default": "Host=localhost; Port=5432; Database=larpake; Username=dev;Password=dev"
  }
}

Run

In MigrationsService folder run

dotnet run build

Generating fake data

Here are instructions how to generate (very) fake data to you dev database. You must have completed steps to run the database migrations that create your larpake_dev PostgreSQL database (see above).

How To Run?

  1. Complete database initialization above Dev database and migrations.

  2. Open TestDataGenerator -project folder

  3. Create file TestDataGenerator\appsettings.Development.json

  4. Paste application configuration to created file

{
  "ConnectionStrings": {
    "PostgreSQL": "Host=localhost; Port=5432; Database=larpake; Username=dev;Password=dev"
  }
}
  1. Open terminal window in the folder and run
dotnet run build
  1. Application runs, if everything went well, last line should read something like
Everything is now ready, press any key to close the application...
  1. Press any button and close the window. Data should now be created.

Clone this wiki locally