SafeChat Back-end Documentation

Kelechi Divine
4 min readOct 28, 2023

--

Introduction

Welcome to our comprehensive technical documentation for SafeChat’s API. This guide provides an in-depth exploration of SafeChat’s implementation, including endpoint resolution, documentation best practices, API consumption tips, and a recipe for creating robust technical solutions.

Furthermore, I’ll provide practical, hands-on experience. Join me as we delve into the world of coding, showcasing the creation of code snippets using the Spring Boot framework. Get ready to savour the rich experience of working with SafeChat’s API, where learning is as rewarding as it is effective.

What is SafeChat

SafeChat is your Ultimate Guardian on Social Media! Savour the delicious peace of mind as SafeChat sweeps through your social feeds like a vigilant taste-tester, meticulously identifying and swiftly eliminating any harmful links. With SafeChat, your online experience becomes a delectable journey through a world of safety and security. Bon appétit for a worry-free social life!

Resolving Endpoints:

We’re thrilled to announce that SafeChat’s backend is now live and successfully deployed on Render. You can access the backend using the following deployment link

https://cyber-mind-deploy.onrender.com

1: Create Account Endpoint

Method: POST

Endpoint: /api/auths/create

Headers: Content-Type: application/json

Description

This endpoint allows you to create a new user within the SafeChat application.

Request Body:

{
"email": "user@example.com",
"password": "your_password_here",
"firstName": "your_first_name",
"lastName" : "lastName",
"gender" : "MALE_or_FEMALE"
}

Responses

HTTP Status: 201 Created

Response Body:

{
"message": "Your account has been created successfully",
"id": "098737490njg329904mks"
}

HTTP Status: 409 Conflict

Response Body:

{
"message": "User with this email already exists"
}

HTTP Status: 500 Internal Server Error

{
"message": "User creation failed"
}

2: Login Endpoint

Method: POST

Endpoint: /api/auths/login

Headers: Content-Type: application/json

Request Body:

{
"email": "user@example.com",
"password": "YourStrongPassword5363@#"
}

Responses

HTTP Status: 200 OK

Response Body:

{
"data": {
"appUser": {
"id": "hi9727729904jnbt656279sji9998",
"email": "user@example.com",
"otherFields": "other_field_values"
},
"token": "jwt_token_here"
}
}

HTTP Status: 401 Unauthorized

Response Body:

{
"message": "Incorrect email or password"
}

HTTP Status: 400 Bad request

Response Body:

{
"message": "Bad request"
}

3: Follow Friend Endpoint

Method: POST

Endpoint: /api/users/follow

Headers: Content-Type: application/json

Request Body:

{
"userId": "user_id_here",
"friendId": "friend_id_here"
}

Responses

HTTP Status: 200 OK

Response Body:

{
"message": "User is now following the friend."
}

Responses

HTTP Status: 404 Not Found

Response Body:

{
"message": "User or friend not found."
}

4: Send Message Endpoint

Method: POST

Endpoint: /api/chats/send-message

Headers: Content-Type: application/json

Request Body:

{
"senderId": "sender_id_here",
"receiverId": "receiver_id_here",
"content": "message_content_here"
}

Responses

HTTP Status: 200 OK

Response Body:

{
"message": "Message processed successfully."
}

Responses

HTTP Status: 404 Not Found

Response Body:

{
"message": "Sender or receiver not found. Message not sent."
}

Responses

HTTP Status: 409 Conflict

Response Body:

{
"message": "Receiver and Sender are the same."
}

Responses

HTTP Status: 406 Not Acceptable

Response Body:

{
"message": "Users are not following each other, so they can not chat."
}

Responses

HTTP Status: 208 Already Reported

Response Body:

{
"message": "Malicious content detected. User has been deleted."
}

Responses

HTTP Status: 400 Bad Request

Response Body:

{
"message": "Bad request"
}

Conclusion

In this documentation, I’ve explored the “send message” endpoint within the SafeChat application. This endpoint allows users to engage in chat conversations while ensuring a secure and positive user experience. I’ve covered the request format, expected responses, and various error scenarios to help you understand how the endpoint functions.

Error Handling

1: HTTP Status 404 Not Found: This error occurs when either the sender or receiver specified in the request is not found in the database. Please ensure that valid user IDs are provided for successful message delivery.

2: HTTP Status 409 Conflict: This conflict status is triggered when the sender and receiver are the same individuals, preventing the message from being sent. It is designed to avoid self-messaging within the system.

3: HTTP Status 208 Already Reported: This status is raised when malicious content is detected in the message content. As a security measure, the user responsible for the malicious content will be removed from the database.

4: HTTP Status 400 Bad Request: This status indicates a general issue with the request or can result from an AppException. Please ensure that your request follows the specified format and handle any AppExceptions accordingly.

5: HTTP Status 406 Not Acceptable: This status is returned when users are not following each other, preventing them from engaging in a chat conversation. Ensure that both users have an established following relationship to initiate a chat.

I hope this documentation serves as a helpful guide for using the “send message” endpoint effectively and safely within SafeChat. If you have any questions or encounter any issues, please don’t hesitate to reach out to me via okoroaforkelechi123@gmail.com or my phone number 09152624528.

SafeChat values the security and satisfaction of its users, and we’re committed to providing a safe and enjoyable messaging experience for all.

Thank you for choosing SafeChat!

--

--