HTTP Server

Using the HTTP Server

The HTTP server provides some basic routes. You can use them as is or extend them to fit your needs.

Set up

To run the HTTP server, only environment variables are needed. You can set them up in your terminal as follows:

export HTTP_SERVER_PORT=8080;
export JWT_SECRET=secretKey;

Note : The default values are the ones used in the example above. You can run the server without setting any environment variables.

API routes

GET /health

Check if the service is up and running.

Response:

{
  "status": "ok"
}

POST /register

Register a new user.

Request body:

{
  "username": "username",
  "password": "password"
}

Response:

{
  "username": "username",
  "password": "password"
}

POST /login

Login with a user.

Request body:

{
  "username": "username",
  "password": "password"
}

Response:

{
  "token": "token"
}

GET /user/:username

Get a user. This route is protected by JWT authentication.

Request header:

{
  "Authorization": "Bearer <auth_token>"
}

Response:

{
  "username": "username",
  "password": "password"
}