Field | Type | Desc |
---|---|---|
_id | ObjectId | auto generated |
username | String | |
String | ||
password_hash | String | encrypted password |
Field | Type | Desc |
---|---|---|
_id | ObjectId | auto generated |
img_src | String | url of image |
desc | String | description of a post |
created_at | Date | date post created |
creator | ObjectId | ref from Account |
likes | Number | number of likes |
liked_by | ObjectId[] | ref from Account |
Field | Type | Desc |
---|---|---|
_id | ObjectId | auto generated |
user | ObjectId | ref from Account |
posts | ObjectId[] | ref from Posts |
liked_posts | ObjectId[] | ref from Posts |
get detailed info of a logged in user
required headers:
Authorization: "token_from_logged_in_user"
response data:
{
"_id": "user_id_from_db",
"username": "loremipsum",
"email": "[email protected]"
}
authenticate a user
request body:
{
"username_or_email": "loremipsum",
"password": "password"
}
response data:
{
"_id": "user_id_from_db",
"username": "loremipsum",
"token": "jsonwebtoken_for_logged_in_user"
}
create an account
request body:
{
"username": "loremipsum",
"email": "[email protected]",
"password": "password"
}
response data:
{
"_id": "user_id_from_db",
"username": "loremipsum",
"token": "jsonwebtoken_for_logged_in_user"
}
change account password
required headers:
Authorization: "token_from_logged_in_user"
request body:
{
"old_password": "old_password",
"new_password": "new_password"
}
get list of all posts
optional query:
page={positive integer}
limit={positive integer}
response data:
{
"page": 1,
"data_length": 20,
"posts": [
{
"_id": "post_id_from_db"
"img_src": "https://url/to/an/image.jpg",
"desc": "description of the post",
"created_at": "string_of_date",
"likes": 12,
"creator": { // undefined if creator doesn't have an account
"_id": "user_id_from_db",
"username": "loremipsum"
} || undefined
},
...
]
}
get detailed info of a post
response data:
{
"_id": "post_id_from_db"
"img_src": "https://url/to/an/image.jpg",
"desc": "description of the post",
"created_at": "string_of_date",
"likes": 12,
"creator": { // undefined if creator doesn't have an account
"_id": "user_id_from_db",
"username": "loremipsum"
} || undefined
}
get post likes data
optional query:
page={positive integer}
limit={positive integer}
response data:
{
"_id": "post_id_from_db",
"page": 1,
"data_length": 20,
"likes": 200
"liked_by": [
{
"_id": "user_id_from_db",
"username": "loremipsum"
},
...
]
}
create a post
optional headers:
Authorization: "token_from_logged_in_user"
request body content:
{
"img_src": "https://url/to/an/image.jpg",
"desc": "description of the post",
}
response body:
{
"_id": "post_id_from_db"
"img_src": "https://url/to/an/image.jpg",
"desc": "description of the post",
"likes": 0,
"creator": { // undefined if creator didn't have an account
"_id": "user_id_from_db",
"username": "loremipsum"
} || undefined
}
like or unlike a post
required headers:
Authorization: "token_from_logged_in_user"
response data:
{
message: "Successfully <like|unlike> <post_id_from_db> post"
}
delete a post
required headers:
Authorization: "token_from_logged_in_user"
response data:
{
message: "Successfully delete <post_id_from_db> post"
}
get user info with list of posts
optional query:
page={positive integer}
limit={positive integer}
response data:
{
"user": {
"_id": "user_id_from_db",
"username": "loremipsum"
},
"page": 1,
"data_length": 20,
"posts": [
{
"_id": "post_id_from_db"
"img_src": "https://url/to/an/image.jpg",
"desc": "desc of the post",
"created_at": "string_of_date",
"likes": 12
},
...
]
}
get user info with list of posts liked
optional query:
page={positive integer}
limit={positive integer}
response data:
{
"user": {
"_id": "user_id_from_db",
"username": "loremipsum"
},
"page": 1,
"data_length": 20,
"liked_posts": [
{
"_id": "post_id_from_db"
"img_src": "https://url/to/an/image.jpg",
"desc": "desc of the post",
"created_at": "string_of_date",
"likes": 12,
"creator": { // undefined if creator doesn't have an account
"_id": "user_id_from_db",
"username": "loremipsum"
} || undefined
},
...
]
}
get list of all users
optional query:
page={positive integer}
limit={positive integer}
response data:
{
"page": 1,
"data_length": 20,
"users": [
{
"_id": "user_id_from_db",
"username": "loremipsum"
},
...
]
}