-
Notifications
You must be signed in to change notification settings - Fork 1
API Routes
https://dbdiagram.io/d/6470f4d67764f72fcfebb2aa
All endpoints that require a current user to be logged in.
-
Request: endpoints that require authentication
-
Error Response: Require authentication
-
Status Code: 401
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Authentication required" }
-
All endpoints that require authentication and the current user does not have the correct role(s) or permission(s).
-
Request: endpoints that require proper authorization
-
Error Response: Require proper authorization
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Forbidden" }
-
Returns the information about the current user that is logged in.
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/session
- Body: none
-
Successful Response when there is a logged in user
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "user": { "id": 1, "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith" } }
-
-
Successful Response when there is no logged in user
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "user": null }
-
Logs in a current user with valid credentials and returns the current user's information.
-
Require Authentication: false
-
Request
-
Method: POST
-
URL: /api/session
-
Headers:
- Content-Type: application/json
-
Body:
{ "email": "[email protected]", "password": "secret password" }
-
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "user": { "id": 1, "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith" } }
-
-
Error Response: Invalid credentials
-
Status Code: 401
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Invalid credentials" }
-
-
Error response: Body validation errors
-
Status Code: 400
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Bad Request", // (or "Validation error" if generated by Sequelize), "errors": { "email": "Email is required", "password": "Password is required" } }
-
Creates a new user, logs them in as the current user, and returns the current user's information.
-
Require Authentication: false
-
Request
-
Method: POST
-
URL: /api/users
-
Headers:
- Content-Type: application/json
-
Body:
{ "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith", "password": "secret password" }
-
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "user": { "id": 1, "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith" } }
-
-
Error response: User already exists with the specified email
-
Status Code: 500
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User already exists", "errors": { "email": "User with that email already exists" } }
-
-
Error response: User already exists with the specified username
-
Status Code: 500
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User already exists", "errors": { "username": "User with that username already exists" } }
-
-
Error response: Body validation errors
-
Status Code: 400
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Bad Request", // (or "Validation error" if generated by Sequelize), "errors": { "email": "Invalid email", "firstName": "First Name is required", "lastName": "Last Name is required" } }
-
Create a new server. User that creates the server will automatically be designated as the owner.
- Require Authentication: true
- Require Proper Authentication: true
- Request
- Method: POST
- Content-Type: application/json
- URL: /api/server
- Body:
{
"name": "new server!",
"imageURL": "something.com",
"userId": 1
}
-
Response
- Successful response when user is logged in:
- Status Code: 201
- Headers:
- Content-Type: application/json
- Body:
- Successful response when user is logged in:
{
"id": 1,
"name": "new server!",
"imageURL": "something.com",
"ownerId": 1,
"createdAt": "06/01/2023"
}
User must be owner of the server in order to delete.
-
Require Authentication: true
-
Require Proper Authentication: true
-
Request
- Method: DELETE
- Content-Type: application/json
- URL: /api/servers/:serverId
- Body: None
-
Response
- Successful response when user is owner of the server
- Status Code: 202
- Headers:
- Content-Type: application/json
- Body:
- Successful response when user is owner of the server
{
"message": "Successfully deleted!"
}
Update the name or image link of a specific server. Only the owner can update the server.
- Require Authentication: true
- Require Proper Authentication: true
- Request
- Method: PUT
- URL: /api/servers/:serverId
- Body:
{
"name": "new name",
"imageURL": "new.image.url.com"
}
Successful Response when there is a logged in user that is the owner of the server
-
Status Code: 202
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "name": "new name!", "imageURL": "new.image.url.com" }
Returns a list of all available servers.
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/servers
- Body: none
-
Successful Response when there is a logged in user
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "Servers": { [ { "id":1, "name":"First server!!!", "owner_id":1, "created_at":"05/30/2023", "image_url": "image.png" }, { "id":2, "name":"second server :(", "owner_id":2, "created_at":"06/01/2023", "image_url": "some.image.com" } ] } }
-
Get servers by User Id~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adds a user to a server as a member.
-
Require Authentication: true
-
User must have the role "owner" or "admin" to add users to a server.
-
Request
-
Method: POST
-
Headers: application/json
-
URL: /api/servers/:serverId/users
-
Body:
{ "userId": 1, "role": "user" //owner, admin, user }
-
-
Successful Response when user is Owner or Admin
-
Status Code: 200
-
Headers: application/json
-
Body:
{ "user_id": 1, "server_id": 1, "role": "user", //user or admin "created_at": "06/01/2023" }
-
Gets the list of members in a server.
-
Require Authentication: true
-
User must be a member of the server with the role "user", "admin", or "owner".
-
Request
- Method: GET
- Headers:
- Content-Type: application/json
- URL: /api/servers/:serverId/users
Update the user role in a server. Only server owners can update roles.
- Require Authentication: true
- Require Proper Authentication: true
- Request
- Method: PUT
- URL: /api/servers/:serverId/users/:userId
- Body:
{
"role": "admin"
}
Successful Response when there is a logged in user that is the owner of the server
-
Status Code: 202
-
Headers:
- Content-Type: application/json
-
Body:
{ "userId": 1, "role": "admin" }
Removes a user's membership to a server. Only a server owner or server admin can remove users. Server admins can not remove other server admins.
- Require Authentication: true
- Require Proper Authentication: true
- Request
- Method: DELETE
- URL: /api/servers/:serverId/users/:userId
- Body: None
Successful Response when the logged in user requesting the delete has the correct server permissions and the userId was found and deleted.
- Status Code: 202
- Headers:
- Content-Type: application/json
- Body:
{
"message": "User sucessfully deleted from server."
}
Returns a list of all available channels within a server
-Require Authentication: true -Request: -Method: GET -URL: /api/channels/:serverId -Body: none
Successful response:
-Status Code: 200 -Headers: -Content-Type: application/json -Body:
{
"categoryName": {
"channelId": {
"name": "General",
"private": "true"
},
"channelId": {
"name": "Memes",
"private": "false"
}
}
}
Create a new channel group for a server.
-
Require Authentication: true
-
Require Authorization: true
-
Request:
- Method: POST
- URL: /api/channelGroups/:serverid
- Body:
{ "name": "Resources" }
Successful Response:
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
{ "id": 1, "server_id": 1, "name": "Resources" }
Error response: Name validation errors
- Status Code: 400
- Headers:
- Content-Type: application/json
- Body:
{ "message": "Bad Request", "errors": { "name": "Name is required", "name": "Group with that name already exists on this server" } }
Create a new channel for a server.
-
Require Authentication: true
-
Require Authorization: true
-
Request:
- Method: POST
- Url: /api/channels/
- Body:
Successful Response:
{ "name": "General", "isPrivate": false, "groupId": 1 }
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "server_id": 1, "group_id": 1, "name": "General", "created_at": "06/01/2023", "isPrivate": false }
Error response: Name validation errors
- Status Code: 400
- Headers:
- Content-Type: application/json
- Body:
{ "message": "Bad Request", "errors": { "name": "Name is required", "name": "Channel with that name already exists on this server" } }
Update an existing channel on a server.
-
Require Authentication: true
-
Require Authorization: true
-
Request:
- Method: PUT
- Url: /api/channels/:id
- Body:
Successful Response:
{ "name": "Rules", "isPrivate": false }
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "server_id": 1, "group_id": 1, "name": "Rules", "created_at": "06/01/2023", "isPrivate": false }
Delete a channel from a server. User must be a role of "admin" or "owner"
-
Require Authentication: True
-
Require Authorization: True
-
Request
- Method: DELETE
- Url: /api/channels/:channelId
- Body: none
Successful Response:
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
{ "message": "Channel successfully deleted" }
Returns a list of all messages in a channel. User must be a member of the server
-
Require Authentication: True
-
Require Authorization: True
-
Request
-
Method: GET
-
URL: /api/channels/:channelId/messages
-
Headers:
-
Content-Type: application/json
-
Body: None
-
-Successful Response when there are conversations
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
"messages": [ { "messageId": 1, "username": "Demo-lition", "messageText": "Hey what's up?", "dateTimeStamp": "1-1-2023 z 01:12:00", "reactions": { "<reactionId>": { "username": "Demo-lition", "emoji": "🙃" } } } ]
Post a new message to a channel.
-
Require Authentication: true
-
Require membership to server of channel: true
-
Request
- Method: POST
- URL: /api/channels/:channelId/messages
- Headers:
- Content-Type: application/json
- Body:
{ "userId": 1, "message": "some message text or something" }
-
Sucessful response when a user is a member of the server and allowed to post to the channel
- Status Code: 201
- Headers:
- Content-Type: application/json
- Body:
{ "message": "Message sent!" }
Edit a message that you sent in a channel
-
Require Authentication: True
-
Require membership to channel: True
-
Request
-
Method: PUT
-
URL: /api/messages/:messageId
-
Header
- Content-Type: application/json
-
Body:
{ "userId": 1, "message": "some message text or something edited" }
-
Successful response when user changes their own message in a channel
-
Status Code: 201
-
Header:
- application/json
-
Body:
{ "messageId": 5, "username": "Demo-lition", "messageText": "some message text or something edited", "dateTimeStamp": "1-1-2023 z 01:12:00" }
Delete a message you sent in a channel
- Require Authentication: True
- Require Proper Authorization: True, user must be the creator of the message or a member of the server with a role of "admin" or "owner"
- Request:
- URL: /api/messages/:messageId
- Method: DELETE
- Headers:
- Content-Type: application/json
- Body:None
React to a message in a channel someone else or you sent
-
Require Authentication: True
-
Require Proper Authorization: False
-
Request
- URL: /api/messages/:messageId/reactions
- Method: POST
- Headers:
- Content-Type: application/json
- Body:
{ "emoji": "❤", "userId": 3 }
-
Successful Response
-
Status Code: 201
-
Header:
- Content-Type: application/json -Body:
"<reactionId>": { "username": "Demo-graphics", "emoji": "🙃" }
-
Returns a list of all users current user has a direct message conversation with
-
Require Authentication: True
-
Request
- Method: GET
- URL: /api/conversations/:userid/
- Headers:
- Content-Type: application/json
- Body: None
-
Successful Response when there are conversations:
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
{ "user1": { "userId": 1, "userIcon": "something.com", "userStatus": "online", "createdAt": "mm/dd/yy", "updatedAt": "mm/dd/yy" }, "user2": { "userId": 2, "userIcon": "somethingelse.com", "userStatus": "online", "createdAt": "mm/dd/yy", "updatedAt": "mm/dd/yy" } }
-
Successful Response when there are no conversations
- Status Code: 200
- Headers
- Content-Type: application/json
- Body:
{ "user": {} }
Returns all messages in a specific user conversation
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/directMessages/:conversationId/
- Headers:
- Content-Type: application/json
- Body: None
-
Successful Response when there are messages
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "UserConversationId": { "messages": [ { "text": "heyyyyyy", "userId": 1, "createdAt": "2021-01-01", "reactions": { "reactionId": { "username": "Demo-graphics", "emoji": "🙃" } } } ] } }
-
-
Successful Response when there are no messages -Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "messages": {} }
-
Create a new user conversation
-
Require Authentication: true
-
Request
-
Method: POST
-
URL: /api/directMessages/:conversationId
-
Body:
{ "text": "heyyyyyy", "userId": 1 }
-
-
Successful Response
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 3, "text": "heyyyyyy", "userId": 1, "createdAt": "mm/dd/yy", "reactions": {} }
-
Create a new user conversation
-
Require Authentication: true
-
Request
-
Method: POST
-
URL: /api/conversations
-
Headers:
- Content-Type: application/json
-
Body:
{ "userId": 2 }
-
-
Successful Response if conversation doesn't already exist
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "conversationId": 1, "createdAt": "mm/dd/yy", "updatedAt": "mm/dd/yy", "user": { "userId": 2, "userIcon": "default.jpg", "userStatus": "online" } }
-
Delete a specific user conversation
-
Require Authentication: true
-
Request
- Method: DELETE
- URL: /api/conversations/:conversationId
- Body: None
-
Successful Response
-
Status Code: 202
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted!" }
-
Delete a specific message in a user conversation.
-
Require Authentication: True
-
Require Authorization: True
-
Request
- Method: DELETE
- URL: /api/directMessages/:messageId
-
Body: None
-
Successful Response
-
Status Code: 202
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted!" }
-
Add a reaction to a specific message in a user conversation
-
Require Authentication: true
-
Request -Method: POST
- URL: /api/directMessages/:messageId/reactions
- Headers:
- Content-Type: application/json
- Body:
{ "emoji": "❤", "userId": 3 }
- URL: /api/directMessages/:messageId/reactions
-
Successful Response
-
Status Code: 201
-
Header:
- Content-Type: application/json -Body:
"<reactionId>": { "username": "Demo-graphics", "emoji": "❤" }
-