Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 2.5 KB

README.md

File metadata and controls

78 lines (60 loc) · 2.5 KB

Chat Room API

Chat Room API Server

About

This is the primary server backing Chat Room. For now, it only offers a simple HTTP JSON API.

The Data Model is built around a concept called Event Sourcing. Basically, every create/update/delete operation is represented as one or more events. The Database contains only those events. In order to get the current state, all events need to be layered on top of each other (aka. aggregated).

Setup

Warning
The API Server expects to be run behind a reverse proxy and thus trusts relevant headers. To prevent abuse of these headers, always run a reverse proxy in front of the API Server.

With Docker Compose

# Build API Server
$ docker compose build app
# Start API Server & Database
$ docker compose up

If you want to compile and run Kotlin manually or via your IDE, only start the Database:

$ docker compose up db

Also, make sure you've set the relevant environment variables (See application.conf).

On Bare Metal

First start your Postgres Database. Ensure you've set the relevant environment variables (See application.conf). Then run the following command in order to build and start the API Server:

$ ./gradlew :api:run

Example

$ curl -H "Authorization: Bearer $API_TOKEN" 'http://localhost:8080/messages?room_id=018562c4-fb64-7a84-b187-aec860bcbff8'
{
    "data": [
        {
            "id": "018562ef-631c-74eb-aadb-22b5a63ad507",
            "memberId": "018562ea-de2d-70d1-b39b-e058a13dc967",
            "content": "Hello",
            "dateCreated": "2022-12-30T12:08:53.788369Z",
            "dateUpdated": "2022-12-30T12:08:53.788369Z"
        },
        {
            "id": "018562ef-89b0-7284-be73-329a16c397aa",
            "memberId": "018562ea-de2d-70d1-b39b-e058a13dc967",
            "content": "World",
            "dateCreated": "2022-12-30T12:09:03.664871Z",
            "dateUpdated": "2022-12-30T12:09:03.664871Z"
        }
    ],
    "list": {
        "offset": null,
        "limit": null,
        "currentItemCount": 2,
        "totalItemCount": 2,
        "totalItemsBefore": 0,
        "totalItemsAfter": 0
    }
}

Limitations

  • No real-time communication since connecting to a raw TCP Socket is not yet supported

License

Copyright (C) Oliver Amann

This project is licensed under the GNU Affero General Public License Version 3 (AGPL-3.0-only). Please see LICENSE for more information.