Welcome to the Social Network's api documentation. This api recreates a fictional database where users can register, log post and like post.
Table of content 📂
Tecnologies used:
- Clon repository
$ npm init --yes
- Instal express
$ npm i express
- Instal nodemon
$ npm i nodemon -D
$ npm i dotenv -E
- Add type module into package.json
{
"type": "module"
}
- Instal mongoose
$ npm i mongoose
- Instal bcrypt
$ npm i bcrypt
- Instal webtoken
$ npm i jsonwebtoken
- User - role: user
{
"name": "user",
"email": "[email protected]",
"password": "123456"
}
- Admin - role: admin
{
"name": "admin",
"email": "[email protected]",
"password": "123456"
}
- Superadmin - role: superadmin
{
"name": "superadmin",
"email": "[email protected]",
"password": "123456"
}
Auth
User Registration
- Register new userRegisters a new user.
POST https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/auth/register
Body:
{
"name": "user",
"email": "[email protected]",
"password": "123456"
}
User Login
-
Login user
User logging using their email and password. POST https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/auth/login
Body:
{
"email": "[email protected]",
"password": "123456"
}
User
Get Users
-
Retrieve all users
Superadmin can retrieve all users registred. GET https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/users
Auth: superadmin's token
superadmin's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Get User's Profile
-
Retrieve user's profile
User can retrieve their profile. GET https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/users/profile
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Update User's Profile
-
Update user's profile
User can update their name. PUT https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/users/profile/
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Body:
{
"name": "newname",
}
Delete User
-
Delete user by id
Superadmin can delete user using their id. DELETE https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/users/:_id
Auth: superadmin's token
superadmin's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Get post by User's id
-
Retrieve posts by user's id
User can retrieve posts from other users by their id. GET https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/users/posts/:userId
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Post
Create Post
-
Create new post
User can create new post. POST https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/posts
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Body:
{
"title": "Post's title",
"text": "Post's text"
}
Update Post
-
Update a post
User can update a post using post's id PUT https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/posts/:_id
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Body:
{
"title": "Post's title updated",
"text": "Post's text updated"
}
Delete Post
-
Delete a post by id
User can delete a post with post's id DELETE https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/posts/:_id
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Get Posts
-
Get all posts
User can get all posts created GET https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/posts/
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Get Post by id
-
Get post by post's id
User can get an specific post by post's id GET https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/posts/:_id
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Get Own Posts
-
Get post own user's post
User can get their own posts GET https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/posts/own
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
Like/Unlike post
-
Put/Pull Like on post
User can like or unlike a post using post's id GET https://social-network-backend-dev-npdx.2.ie-1.fl0.io/api/posts/like/:_id
Auth: user's token
user's credentials:
{
"email": "[email protected]",
"password": "123456"
}
- Ana Rius - student FSD
Special thanks to Daniel Tarazona for his incredible work as a teacher and above all for his infinite patience in helping to resolve any doubts and calm the panic.
Thanks to my classmates:
Pedro for his patience and help, especially to confirm that I understand things.
Marina and Marta for her moral support, with laughter and tears, as well as their help.