OlexG / branham-chat

0 stars 1 forks source link

API Spec #19

Closed mattfbacon closed 2 years ago

mattfbacon commented 2 years ago

API Specification

Note: the frontend is available at the root.

Basic Types

Members marked with #[request] are used for requests.

type Id = <some integral type>;

struct Message {
  id: Id,
  #[request]
  content: String,
  timestamp: u64,
  #[serde(flatten)]
  user: User,
}

struct User {
  #[serde(rename = "user_name")]
  name: String,
  #[serde(rename = "user_picture")]
  picture: String,
}

struct Room {
  #[request]
  id: Id,
  name: String,
}

#[serde(tag = "type", rename_all = "snake_case")]
enum MessageEvent {
  NewMessage(Message),
  DeleteMessage{ id: Id },
}

HTTP Endpoints

GET /rooms/<room name>/messages

Returns the messages in a room as an array of Messages.

Response type: [Message]

POST /rooms/<room name>/messages

Sends a message to a room.

Request type: Message (#[request] fields only) Response type: Message

POST /login

Gets a user token from an OAuth token.

Request type: struct { token: String } Responds with 204; token is in header X-User-Token.

WebSocket Protocol

/rooms/<room name>/messages.ws

Server sends a series of MessageEvents. Client does not send anything.

Sptele commented 2 years ago

What is the struct syntax? Is that typescript?

mattfbacon commented 2 years ago

Rust 😈

mattfbacon commented 2 years ago

Closing this as we have moved it to be a file in the root of the project. That way it can be version-controlled.