ikisocket_chat_room_example

package
v0.0.0-...-a764a30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 8 Imported by: 0

README

Chat room example

Disclaimer:

This my personal interpretation of a basic chatroom example, with basic API to handle the rooms. Please feel free to add comments or suggestions here

REST API for room management

Rooms

CREATE

  • Method: POST
  • Endpoint: [API-URL]/rooms/create
  • Description: Create a room via API passing JSON name

PARAMS

  • name (mandatory)
{
  "name":"Best Room ever"
}

RESPONSE

{
  "name": "Best Room ever",
  "uuid": "xgYENKyyAdOdrSZb5JNMAu1g7iEGlaE77cEEZgaHg3n5dGWaFG2IV0Nru6C1QEAKh2F9CL4I8uxW1CK5ev0g9mnJTHy0pBSrndGg",
  "users": null // list of users in that room
}

GET

  • Method: GET
  • Endpoint: [API-URL]/rooms
  • Description: Retrieve all the rooms created

RESPONSE

[
  {
    "name": "Best Room ever",
    "uuid": "xgYENKyyAdOdrSZb5JNMAu1g7iEGlaE77cEEZgaHg3n5dGWaFG2IV0Nru6C1QEAKh2F9CL4I8uxW1CK5ev0g9mnJTHy0pBSrndGg",
    "users": null
  }
]

DELETE ROOM

  • Method: DELETE
  • Endpoint: [API-URL]/rooms/delete/[UUID]
  • Description: Delete room by UUID

PARAMS

  • Room UUID (mandatory)

RESPONSE

true

JOIN

  • Method: POST
  • Endpoint: [API-URL]/rooms/join
  • Description: Join the room passing room id and user id

PARAMS

  • room (Room UUID | Mandatory)
  • user (User ID | Mandatory)
{
  "user":"1",
  "room":"xgYENKyyAdOdrSZb5JNMAu1g7iEGlaE77cEEZgaHg3n5dGWaFG2IV0Nru6C1QEAKh2F9CL4I8uxW1CK5ev0g9mnJTHy0pBSrndGg"
}

RESPONSE

true|false

Connect to the websocket

ws://localhost:3000/ws/<user-id>

Message object example

{
    "from": "<user-id>",
    "to": "<recipient-user-id>",
    "room": "<room-id>",
    "data": "hello"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageObject

type MessageObject struct {
	Data string `json:"data"`
	From string `json:"from"`
	Room string `json:"room"`
	To   string `json:"to"`
}

MessageObject Basic chat message object

type Room

type Room struct {
	Name  string   `json:"name"`
	UUID  string   `json:"uuid"`
	Users []string `json:"users"`
}

Room Chat Room message object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL