
-ChatBox-
This project is a fullstack web application designed to achieve communication between users in real-time through websockets.
Tech Stack
Client: Vue, Vuetify
Server: Go, Chi, MongoDB
Infra: Docker, Render
API Reference
Base URL
https://chatbox-back.onrender.com
Websocket
wss://chatbox-back.onrender.com
Routes
Public:
Authorization required:
I opted to store values such as access tokens, user id's and session id's in localStorage
for the sake of simplicity, easy debugging and straightforward management of session data during development of frontend. I am fully aware of the potential security risks associated with this type of data management.
User SignUp
POST /signup
Request body
{
"name": "John Doe"
"password": "1234"
}
Headers |
Value |
Content-Type |
application/json |
Response
{
"access_exp": "2024-09-14T02:53:10Z",
"access_token": "eyJhbGciOiJ...",
"message": "User added successfully",
"refresh_exp": "2024-09-15T02:38:10Z",
"session_id": "ce8306f9-d614-4439-8337-8f7efdeff1b1",
"user": {
"id": "66e4f71243d2b68b40ca71ac",
"name": "John Doe"
}
}
User SignIn
POST /signin
Headers |
Value |
Content-Type |
application/json |
Request body
{
"name": "John Doe"
"password": "1234"
}
Response
{
"access_exp": "2024-09-14T02:56:28Z",
"access_token": "eyJhbGciOiJ...",
"message": "User logged successfully",
"refresh_exp": "2024-09-15T02:41:28Z",
"session_id": "5aeb2038-2e16-4ba3-85c7-672ebd6a6a5b",
"user": {
"id": "66e4f71243d2b68b40ca71ac",
"name": "John Doe"
}
}
User Logout
DELETE /logout/{session-id}
Response
{
"message": "User logged out"
}
Renew Token
POST /token/renew/{session-id}
Response
{
"access_exp": "2024-09-14T03:07:52Z",
"access_token": "eyJhbGciOiJ...",
"message": "Access token renewed"
}
Revoke Token
POST /token/revoke/{session-id}
Response
204 No Content (Revoked successfully)
User Data
GET /user/{id}
Headers |
Value |
Authorization |
access-token |
Response
{
"claims": {
"expires_at": "Sat Sep 14 04:19:44 2024",
"subject": "312a36d6-178e-4f14-b671-bd6d0e656c4f"
},
"message": "User data retrieved",
"user_data": {
"id": "66e4f71243d2b68b40ca71ac",
"name": "John Doe",
"personal": {
"Email": "john@gmail.com",
"Country": "United States",
"Age": 32
}
}
}
Save Personal Data
PUT /user/save-personal/{id}
Headers |
Value |
Content-Type |
application/json |
Authorization |
access-token |
Request body
{
"email": "johndoe@gmail.com",
"age": 32,
"country": "United States"
}
Response
{
"message": "Personal data saved successfully"
}
Add Chat
POST /chat
Headers |
Value |
Content-Type |
application/json |
Authorization |
access-token |
Request body
{
"username": "Jane Doe",
"petitioner_id": "66e4f71243d2b68b40ca71ac",
"petitioner": "John Doe"
}
Response
{
"chat": {
"id": "66e5ab4cdff129912cd0e80b",
"participants": [
{
"id": "66e5ab40dff129912cd0e80a",
"name": "Jane Doe"
},
{
"id": "66e4f71243d2b68b40ca71ac",
"name": "John Doe"
}
]
},
"contact": {
"username": "Jane Doe",
"petitioner_id": "66e4f71243d2b68b40ca71ac",
"petitioner": "John Doe"
},
"message": "Chat added successfully"
}
Load Chats
GET /chat/{user-id}
Headers |
Value |
Content-Type |
application/json |
Authorization |
access-token |
Response
{
"chats": [
{
"id": "66e5ab4cdff129912cd0e80b",
"participants": [
{
"id": "66e4f71243d2b68b40ca71ac",
"name": "John Doe"
},
{
"id": "66e35284b75d98c6ce1a58c7",
"name": "Jane Doe"
}
]
},
[...]
],
"message": "User chats retrieved"
}
Delete Chat
DELETE /chat/{chat-id}
Headers |
Value |
Content-Type |
application/json |
Authorization |
access-token |
Response
{
"message": "Chat deleted successfully"
}
Load Messages
GET /chat/{chat-id}/messages
Headers |
Value |
Content-Type |
application/json |
Authorization |
access-token |
Response
{
"message": "Messages loaded",
"messages": [
{
"id": "66e65747c19386daf16f545e",
"chat_id": "66e5ab4cdff129912cd0e80b",
"sender_id": "66e4f71243d2b68b40ca71ac",
"content": "Hello",
"sent_at": "2024-09-15T03:40:55.063Z"
},
[...]
]
}
Send Message
WEBSOCKET /ws/send-msg
Parameters |
Value |
wsauth |
access-token |
Request body
{
"chat_id": "66e5ab4cdff129912cd0e80b",
"sender_id": "66e4f71243d2b68b40ca71ac",
"content": "Hello"
}
Response
{
"message": "Message was sent successfully"
"new_message": {
"id": "66e65747c19386daf16f545e",
"chat_id": "66e5ab4cdff129912cd0e80b",
"sender_id": "66e4f71243d2b68b40ca71ac",
"content": "Hello",
"sent_at": "2024-09-15T03:40:55.063Z"
}
}
Edit Message
WEBSOCKET /ws/edit-msg
Parameters |
Value |
wsauth |
access-token |
Request body
{
"message_id": "66e65747c19386daf16f545e",
"new_message": "Bye"
}
Response
{
"message": "Message edited successfully"
"new_message": {
"id": "66e65747c19386daf16f545e",
"chat_id": "66e5ab4cdff129912cd0e80b"
"sender_id": "66e4f71243d2b68b40ca71ac",
"content": "Bye",
"sent_at": "2024-09-15T03:40:55.063Z"
}
}
Delete Message
WEBSOCKET /ws/del-msg
Parameters |
Value |
wsauth |
access-token |
Request body
Message ID in Text format
66e65747c19386daf16f545e
Response
{
"message": "Message deleted successfully"
"message_id": "66e65747c19386daf16f545e"
}