-
Notifications
You must be signed in to change notification settings - Fork 0
TwitterBaby_Backend_Documentation
q to shutdown server
i to reconstruct database to default (w/ some initial collections)
r to reconstruct testing database
All routes except Login, Signup and GetWSConnection, need to have a Authorization header, which contains a JWT.
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA
Return user info for a specific user, and whether it is followed by the current user.
/api/v1/userInfo/:username
GET
username = [alphanumeric]
Code: 200 OK
Content:
{
"userinfo": {
"username": "TomRiddle",
"firstname": "Tom",
"lastname": "Riddle",
"email": "[email protected]",
"bio": "Hi everyone, this is Lord Voldemort.",
"tag": "Voldemort"
},
"followercount": 12,
"followingcount": 5,
"followed": true
}
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -X GET http://localhost:1323/api/v1/userInfo/TomRiddle -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA'
# Response does not include the full list of followers and following, only the counts.
Add a specific username to the current user's following set, and add current user to that user's follower list.
/api/v1/follow/:username
POST
username = [alphanumeric]
Code: 200 OK
Content: user's following list
[
"JasonHe",
"MarsLee",
"TomRiddle",
"test115415",
"JasonHo"
]
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -X POST http://localhost:1323/api/v1/follow/JasonHo -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA'
Remove a specific username from the current user's following set, and remove current user from that user's follower list.
/api/v1/unfollow/:username
POST
username = [alphanumeric]
Code: 200 OK
Content: user's following list
[
"JasonHe",
"TomRiddle",
"test115415",
"JasonHo"
]
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -X POST http://localhost:1323/api/v1/unfollow/JasonHo -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA'
Login to an account associated with the email address and the password.
/api/v1/login
POST
{
"email":"[email protected]",
"password":"test1"
}
Parameter | Description | Type | Required |
---|---|---|---|
user's email address | alphanumeric | Yes | |
password | user's password | alphanumeric | Yes |
Code: 200 OK
Content: user data (contains a JWT)
{
"username": "JasonHo",
"firstname": "Jason",
"lastname": "Hoo",
"email": "[email protected]",
"followers": [
"MarsLee",
"TomRiddle"
],
"following": [
"JasonHe",
"MarsLee",
"TomRiddle",
],
"bio": "Jason Ho is unstoppable!",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA"
}
Code: 401 Unauthorized (If an account associated with the email address and password is not found.)
Content:
{
"message": "Invalid email or password."
}
curl -X POST http://localhost:1323/api/v1/login -H 'Content-Type: application/json' -d '{"email":"[email protected]","password":"test1"}'
Create an user instance.
/api/v1/signup
POST
{
"username":"eve",
"firstname":"Evelyn",
"lastname":"Clarkson",
"password":"pass",
"email":"[email protected]",
"bio":"Hi, this is Evelyn!",
"tag":"Angel",
"picture":"GVk/1ysJQC/DxcdC2QMQ6J/tylP77IEUsm3WnppWFoQsVuuNp/VqQRAMm8jT"
}
Parameter | Description | Type | Required |
---|---|---|---|
username | user's email address | alphanumeric | Yes |
firstname | user's firstname | alphanumeric | Yes |
lastname | user's lastname | alphanumeric | No |
password | user's password | alphanumeric | Yes |
user's email | alphanumeric | Yes | |
bio | user's biography | alphanumeric | No |
tag | user's personal tag | alphanumeric | No |
picture | user's picture | base 64 string | No |
Code: 201 Created
Content: user data
{
"username": "eve",
"firstname": "Evelyn",
"lastname":"Clarkson",
"email":"[email protected]",
"bio":"Hi, this is Evelyn!",
"tag":"Angel",
"picture":"GVk/1ysJQC/DxcdC2QMQ6J/tylP77IEUsm3WnppWFoQsVuuNp/VqQRAMm8jT"
}
Code: 400 Bad Request (If one of username, firstname, email, password is empty, or username, email already used.)
Content:
{
"message": "Username or email already used."
}
curl -X POST http://localhost:1323/api/v1/signup -H 'Content-Type: application/json' -d '{"username":"eve","firstname":"Evelyn","password":"pass","email":"[email protected]"}'
Return the follower list for a specific user, along with some followers info.
/api/v1/showFollower/:username
GET
username = [alphanumeric]
Code: 200 OK
Content: followers' info
[
{
"username": "JasonHo",
"firstname": "Jason",
"lastname": "Hoo",
"bio": "Jason Ho is unstoppable!"
},
{
"username": "TomRiddle",
"firstname": "Tom",
"lastname": "Riddle",
"bio": "Hi everyone, this is Lord Voldemort."
}
]
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -X GET http://localhost:1323/api/v1/showFollower/TomRiddle -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA'
Return the following list for a specific user, along with some followings info.
/api/v1/showFollowing/:username
GET
username = [alphanumeric]
Code: 200 OK
Content: followings' info
[
{
"username": "TomRiddle",
"firstname": "Tom",
"lastname": "Riddle",
"bio": "Hi everyone, this is Lord Voldemort."
},
{
"username": "test115415",
"firstname": "Jason",
"lastname": "He"
}
]
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -X GET http://localhost:1323/api/v1/showFollowing/TomRiddle -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA'
Update a user's info, only firstname, lastname, bio, and tag are allowed to be modified.
/api/v1/updateUserInfo
POST
{
"firstname":"Evelyn",
"lastname":"Clarkson",
"bio":"Hi, this is Evelyn!",
"tag":"Angel"
}
Parameter | Description | Type | Required |
---|---|---|---|
firstname | user's firstname | alphanumeric | Yes |
lastname | user's lastname | alphanumeric | Yes |
bio | user's biography | alphanumeric | Yes |
tag | user's personal tag | alphanumeric | Yes |
Code: 200 OK
Content: user data
{
"username": "eve",
"firstname": "Evelyn",
"lastname":"Clarkson",
"email":"[email protected]",
"bio":"Hi, this is Evelyn!",
"tag":"Angel",
"picture":"GVk/1ysJQC/DxcdC2QMQ6J/tylP77IEUsm3WnppWFoQsVuuNp/VqQRAMm8jT"
}
Code: 400 Bad Request (If one or more fields are empty.)
Content:
{
"message": "All fields must not be empty."
}
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -X POST http://localhost:1323/api/v1/updateUserInfo -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA' -d '{"firstname":"Jason","lastname":"Ho","bio":"","tag":""}'
# Request body must contain all four fields, even if they are empty or not modified.
Update a user's profile picture, or remove profile picture by sending an empty string.
/api/v1/updateProfilePic
POST
{
"picture":"iVBORw0KGgoAAAANSUhEUgAAACAAIrGAAAAjVBMVEXp6en///+8vLwPZ66L1fPY"
}
Parameter | Description | Type | Required |
---|---|---|---|
picture | user's picture | base 64 string | Yes |
Code: 201 Created
Content: user data
{
"username": "eve",
"firstname": "Evelyn",
"lastname":"Clarkson",
"email":"[email protected]",
"bio":"Hi, this is Evelyn!",
"tag":"Angel",
"picture":"GVk/1ysJQC/DxcdC2QMQ6J/tylP77IEUsm3WnppWFoQsVuuNp/VqQRAMm8jT"
}
Code: 400 Bad Request (If the image is larger than 10 MB.)
Content:
{
"message": "Image must be smaller than 10 MB."
}
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -X POST http://localhost:1323/api/v1/updateProfilePic -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1MzQ1NTgsInVzZXJuYW1lIjoiSmFzb25IbyJ9.0hr1JjZCKaBuL1-pn7ddzkUUbxCIKHddhsx56IUYXeA' -d '{"picture":"iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAjVBMVEXp6en///+8vLwPZ66L1fPY"}'
# Image is to be encoded into base 64 string, and cannot be larger than 10 MB.
Upgrade a client connection to websocket.
/api/v1/ws/:username
GET
username = [alphanumeric]
Code: 201 Created on success
Content: user data
{
"username": "eve",
"firstname": "Evelyn",
"lastname":"Clarkson",
"email":"[email protected]",
"bio":"Hi, this is Evelyn!",
"tag":"Angel",
"picture":"GVk/1ysJQC/DxcdC2QMQ6J/tylP77IEUsm3WnppWFoQsVuuNp/VqQRAMm8jT"
}
Code: 400 Bad Request (If failed to make connection.)
Content:
{
"message": "Failed to make web socket connection."
}
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User does not exist."
}
curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: localhost:1323" -H "Origin: http://localhost:1323" -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" -H "Sec-WebSocket-Version: 13" http://localhost:1323/api/v1/ws/JasonHo
Delete a specific tweet.
/api/v1/deleteTweet/:tweet
DELETE
tweet = [alphanumeric]
Code: 200 OK
Content:
{
}
Code: 400 Bad Request if tweet ID is malformed. Content:
{
"message": "Malformed tweet ID."
}
Code: 404 Not Found if the tweet is not in the database. Content:
{
"message": "Tweet does not exist."
}
curl -X DELETE http://127.0.0.1:1323/api/v1/deleteTweet/59fb210c311bc3079616e46e -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDk4ODkzMDksInVzZXJuYW1lIjoiSmFzb25IbyJ9.46md5Q1-fg79egQPZ0kEqqbC3WK9jRGsnwan67y3x7s'
Handle requests asking for a list of tweets posted by a specific user.
/api/v1/tweetlist/:username
GET
username = [alphanumeric]
page = [number]
perpage = [number]
Code: 200 OK on success.
Content: tweet data
{
“Page”: “1”,
"totalpage": “2”,
"totaltweets”:”2”,
"tweetlist":[
{
"id":"59ff683957a437fc2475164f",
"owner":"JasonHo",
"message":"I love Florida!",
"numcomment":0,
"timestamp":"2017-11-05T14:36:25.852-05:00"
},
{
"id":"59ff683957a437fc2475164f",
"owner":"JasonHo",
"message":"I love Florida!",
"numcomment":0,
"timestamp":"2017-11-05T14:36:25.852-05:00"
}
]
}
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User [username] does not exist."
}
curl -X GET 'http://127.0.0.1:1323/api/v1/tweetlist/JasonHo?page=1&perpage=6' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTAwNjMzOTksInVzZXJuYW1lIjoiSmFzb25IbyJ9.WyNqjjuWBGd4oeiM68l2mRqRMXO-asdb7by7b7imKdU'
Handle requests asking for a list of tweets timeline from the following list of specific user.
/api/v1/tweettimeline/:username
GET
username = [alphanumeric]
page = [number]
perpage = [number]
Code: 200 OK on success.
Content: tweetTimeline data
{
“Page”: “1”,
"totalpage": “2”,
"totaltweets”:”2”,
"tweetlist":[
{
"id":"59ff683957a437fc2475164f",
"owner":"JasonHo",
"message":"I love Florida!",
"numcomment":0,
"timestamp":"2017-11-05T14:36:25.852-05:00"
},
{
"id":"59ff683957a437fc2475164f",
"owner":"JasonHo",
"message":"I love Florida!",
"numcomment":0,
"timestamp":"2017-11-05T14:36:25.852-05:00"
}
]
}
Code: 404 Not Found (If the user is not in the database.)
Content:
{
"message": "User [username] does not exist."
}
curl -X GET 'http://127.0.0.1:1323/api/v1/tweettimeline/JasonHo?page=1&perpage=24' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDk4ODkzMDksInVzZXJuYW1lIjoiSmFzb25IbyJ9.46md5Q1-fg79egQPZ0kEqqbC3WK9jRGsnwan67y3x7s'
Add one tweet for a specific user.
/api/v1/newTweet
POST
{
"message":"Test comment"
"picture":"iVBORw0KGgoAAAANSUhEUgAAACAAIrGAAAAjVBMVEXp6en///+8vLwPZ66L1fPY"
}
Parameter | Description | Type | Required |
---|---|---|---|
picture | user's picture | base 64 string | Yes |
Code: 201 Created
Content: tweet data
{
“owner”: “MarsLee”,
“Message”: “Hi wow”,
"picture":"GVk/1ysJQC/DxcdC2QMQ6J/tylP77IEUsm3WnppWFoQsVuuNp/VqQRAMm8jT"
}
Code: 400 Bad Request (If the image is larger than 10 MB.)
Content:
{
"message": "Image must be smaller than 10 MB."
}
Code: 400 Bad Request (If the image is larger than 10 MB.)
Content:
{
"message": "Message cannot be empty."
}
curl -X POST http://127.0.0.1:1323/api/v1/newTweet -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTAwNjMzOTksInVzZXJuYW1lIjoiSmFzb25IbyJ9.WyNqjjuWBGd4oeiM68l2mRqRMXO-asdb7by7b7imKdU' -d '{"message":"Test comment", "picture":"iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAjVBMVEXp6en///+8vLwPZ66L1fPY"}'
# Image is to be encoded into base 64 string, and cannot be larger than 10 MB.
Add one comment for a specific tweet.
/api/v1/newcomment/:tweet
POST
tweet = [alphanumeric]
{
"message”:”test message“
}
Code: 200 Created comment Content: comment data
{
"FromTweetID": "59fdd076311bc30ffb5592b1 ",
"FromUsername": “MarsLee”,
"Message”:”Test test test“
}
Code: 400 Bad Request (Bad Request if the content of the comment is empty.)
Content:
{
"message": "Message cannot be empty."
}
Code: 404 Not Found (Not Found if the tweetID is not in the database.)
Content:
{
"message": "Invalid tweet ID"
}
curl -X POST http://127.0.0.1:1323/api/v1/newcomment/59fdd076311bc30ffb5592b1 -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTAwNjMzOTksInVzZXJuYW1lIjoiSmFzb25IbyJ9.WyNqjjuWBGd4oeiM68l2mRqRMXO-asdb7by7b7imKdU' -d '{"message":"Are your kidding me?"}'
Handle requests asking for a list of comment depend on a specific tweet.
/api/v1/fetchcomment/:tweet
GET
tweet = [alphanumeric]
Code: 200 OK on success.
Content: tweet data
{
“totalcomment”: “2”,
"CommentList":[
{
"_id": {
"$oid": "59ffc54c9d1fa261b27901a3"
},
"fromtweetid": "59fdd076311bc30ffb5592b1",
"fromusername": "JasonHo",
"message": "Comment2",
"timestamp": {
"$date": "2017-11-06T02:13:32.915Z"
}
},
{
"_id": {
"$oid": "59ffc54c9d1fa261b27901a3"
},
"fromtweetid": "59fdd076311bc30ffb5592b1",
"fromusername": "JasonHo",
"message": "Comment2",
"timestamp": {
"$date": "2017-11-06T02:13:32.915Z"
}
},
]
}
Code: 404 Not Found (if the tweetID is not in the database.)
Content:
{
"message": "Invalid tweet ID"
}
curl -X GET http://127.0.0.1:1323/api/v1/fetchcomment/59fdd076311bc30ffb5592b1 -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTAwNjMzOTksInVzZXJuYW1lIjoiSmFzb25IbyJ9.WyNqjjuWBGd4oeiM68l2mRqRMXO-asdb7by7b7imKdU'
Retweet a tweet.
/api/v1/reTweet
POST
{
"message":"Test retweet",
"Idretweet":"59feca729d1fa25e894ad8d0"
}
Code: Created on success, along with the retweet data. Content: user data
{
“owner”: “MarsLee”,
“message”: “test”,
"ownerretweet”:”JasonHo”,
"messageretweet”:”Retweet message”,
"picture":"GVk/1ysJQC/DxcdC2QMQ6J/tylP77IEUsm3WnppWFoQsVuuNp/VqQRAMm8jT"
}
Code: 400 Bad Request (If the image is larger than 10 MB.)
Content:
{
"message": "Image must be smaller than 10 MB."
}
Code: 400 Bad Request (if the content of the retweet is empty.)
Content:
{
"message": "Message cannot be empty."
}
Code: 404 Not Found (if the tweet is not in the database.)
Content:
{
"message": "Invalid tweet ID"
}
curl -X POST http://127.0.0.1:1323/api/v1/reTweet -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTE1NzI3MDcsInVzZXJuYW1lIjoiSmFzb25IbyJ9.Ic1GsRvF3gxmUtbRhlSaFFF8JQVtnLLNYw0PYZeeFJY' -d '{"Idretweet":"59feca729d1fa25e894ad8d0", "message":"Test retweet"}'
After a websocket connection is established, the server will dump all unacked notifications to the browser, in timestamp ascending order(oldest first).
Whenever there is a new tweet from any of the followees of the current user, the server will push a new tweet notification to the current user's browser.
Text
"New tweets."
Whenever a new follower follows the current user, the server will push a follow notification to the current user's browser, containing the timestamp and the follower.
JSON
{
"timestamp":"2017-11-04T18:13:03.902-04:00",
"type":"Follow",
"detail":"TomRiddle"
}
If a client sends a clear notifications message to the server, the server will then remove all notifications from the unacked notification list.
Text
"Clear notifications."