package
0.0.0-20220602195234-a764a30426a0
Repository: https://github.com/sculas/ikisocket.git
Documentation: pkg.go.dev

# 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"
}