Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Added api definition #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions docs/protocol/daemon-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Daemon Api

The Daemon Api is the api that provides the communication between the Server and a Daemon.
All interactions are instantiated from the Server.
<br>
This api is used to provide the frontend capability to instantiate game processes.

## Structure

The Daemon Api is something like a Rest Api on the Daemon witch is accessed from the Server.
<br>
Every enpoint follows the following schema: `<endpoint-collection>/<endpoint>`

| Name | Description |
|------|-------------|
| Endpoint Collection | As the name says, a endpoint collection is a collection of endpoints. All endpoints from a collection are from the same daemon. The purpose of a endpoint collection is to group certain endpoints. (e.g. `network` contains all endpoints related to networks) |
| Endpoint | A endpoint is like a function on a daemon witch can be executed by the frontend. Mostly it changes database stated or sends notifications to other users. |

## Security

In normal cases all daemons are not public accessible. (e.g. secured by a firewall or Docker Networks)
<br>
Although all request must contain an api token. The api token can be configured with an environment variable on the server and Dameon side.
It is recommended to change the api token is regular time spans.

## Request

### Header

The server sends the following headers:

```http
Content-Type: application/json; charset=utf-8
Accept: application/json
Accept-Charset: utf-8
Authorization: <api token>
```

### Body

The server sends the following parameters:

```json
{
"user_id": "<uuid>" // the id of the user who executed the endpoint
// ... - endpoint specific parameters
}
```

## Response

### Header

The daemon must respond with the following headers:

```http
Content-Type: application/json; charset=utf-8
```

The status code is also passed to the frontend.

### Body


The daemon must respond with the following body:

```json
{
"error": "message" // optional error message
// ... - endpoint specific data
}
```

## Endpoint Discovery

When a server boots, it discovers all existing endpoints. Therefore, it executes the discovery endpoint for every Dameon type.
This is needed to filter out request for non-existing endpoints and to route requests to the daemon according to the endpoint.
<br>
<br>
The response looks like this:

```json
[
{
"id": "<endpoint collection id>",
"description": "<endpoint collection description>",
"disabled": false,
"endpoints": [
{
"id": "<endpoint id>",
"description": "<endpoint description>",
"disabled": false
}
]
}
]
```

_The description is currently not used._
13 changes: 13 additions & 0 deletions docs/protocol/notification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Create redis hash:
```
$ hset notification:<UUID> data <JsonElement> id <UUID> topic <string>
```

Notify server of new notification:
```
$ subscribe notifications
1) "message"
2) "notifications"
3) "<userId>:<notificationId>"

```
71 changes: 71 additions & 0 deletions docs/protocol/websocket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Websocket Api

The websocket api is the interface for any frontend to communicate with the backend.
<br>
By default the websocket is available at `/ws`. (e.g. `wss://server.cryptic-game.net/ws`)

## Request

```json
{
"tag": "random string",
"endpoint": "user/register",
"data": {
"username": "TestUser",
"password": "#Test123"
}
}
```

| Name | Description |
|------------|----------------------------------------------------------------------------------------------------------------|
| `tag` | The tag is a random string witch is copied to the response of this request to identify the according response. |
| `endpoint` | The endpoint witch should be executed. |
| `data` | The data witch should be passed to the endpoint. |

## Response

```json
{
"status": {
"code": 200,
"name": "OK"
},
"error": "<message>", // optional
"tag": "random string",
"data": {
"id": "fd973bf5-3801-402f-8c85-d5313aa02baa",
"user_id": "2cea82a0-3425-4d0e-8e1b-4823ad744162"
}
}
```

| Name | Description |
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `status` | The status code and name of the response. The codes are similar to the [Http Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). |
| `error` | A optional error message. |
| `tag` | The same value as in the request. |
| `data` | A optional data witch the endpoint produced. |

## Notification

```json
{
"status": {
"code": 900,
"name": "Notification"
},
"topic": "MESSAGE_SEND",
"data": {
"user_id": "fd973bf5-3801-402f-8c85-d5313aa02baa",
"whisper": false,
"content": "Hello"
}
}
```

| Name | Description |
|----------|--------------------------------------------------------------------|
| `status` | The status is in every Notification the same. |
| `topic` | The topic of the notification. It can be interpreted as a channel. |
| `data` | A optional data of the notification. |
5 changes: 5 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ extra:
link: https://github.com/cryptic-game
- icon: fontawesome/brands/twitter
link: https://twitter.com/Cryptic_Game

markdown_extensions:
- pymdownx.highlight:
linenums: true
- pymdownx.superfences