Social-backend is a backend for a social networking application (such as Twitter/X) created for educational purposes.
- User register
- Login
- Create posts (Text only)
- Delete posts [WIP]
- Create comments
- Delete comments [WIP]
- Like posts
- Like comments
- Follow users
- Block users [WIP]
- Get timeline
- Upload profile picture
- Delete profile picture
Clone the project
git clone [email protected]:SantiagoPintos/social-backend.git
Go to the project directory
cd social-backend
Install dependencies
npm install
Start the server
npm run start:prod
To run this project, you will need to add the following environment variables to your .env file
JWT_SECRET
POST /users/register
Parameter | Type | Description |
---|---|---|
name |
string |
Required. |
lastName |
string |
Required. |
username |
string |
Required. |
email |
string |
Required. |
password |
string |
Required. |
POST /users/login
Parameter | Type | Description |
---|---|---|
username |
string |
Required. |
password |
string |
Required. |
Returns a unique token per device por login.
Example:
{
"message": "User successfully logged in.",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwidXNlcm5hbWUiOiJzYW50aWFnbyIsImVtYWlsIjoic2FudGlhZ29AZ21haWwuY29tIiwiaWF0IjoxNzEyNDMwOTE2fQ.S-CpQ1OrjwsI0RlIKotC-opz8EXEW3B5U2lH1p460q8"
}
POST /users/follow/:id
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
Returns a message with the confirmation/error.
Example:
{
"message": "User followed",
}
POST /users/profile-image
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
File |
image |
Required. |
Returns a message with the confirmation/error.
Example:
{
"message": "Profile image updated successfully",
}
DELETE /users/profile-image
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
Returns a message with the confirmation/error.
Example:
{
"message": "Profile image deleted successfully",
}
POST /publications
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
content |
string |
Required. |
userId |
string |
Required. |
Returns an object with the content of the new post.
{
"message": "Post created successfully",
"post": {
"autorId": 2,
"content": "Hey! This is my first post!",
"date": "2024-04-06T19:19:05.290Z",
"likes": 0,
"id": 1
}
}
GET /publications
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
numberOfPosts |
number |
Optional. |
postId |
number |
Optional. |
Returns a list of the user's posts.
{
"posts": [
{
"id": 1,
"autorId": 2,
"content": "Hey! This is my first post!",
"date": "2024-04-06T19:19:05.290Z",
"likes": 0,
"comments": []
}
]
}
POST /publications/{postId}/comments
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
comment |
string |
Required. |
postId |
string |
Required. |
Returns an object with the comment and its parent post.
{
"message": "Comment created successfully",
"post": {
"autorId": 2,
"content": "This is the first comment to my post!",
"date": "2024-04-06T19:57:24.623Z",
"likes": 0,
"parentPost": {
"id": 1,
"autorId": 2,
"content": "Hey! This is my first post!",
"date": "2024-04-06T19:19:05.290Z",
"likes": 0
},
"id": 3
}
}
POST /like/{type}/{id}
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
userId |
string |
Required. |
Returns an object with the confirmation message
{
"message": "Like removed"
}
Or
{
"message": "Like created successfully",
"like": {
"userId": 1,
"publicationId": 1,
"date": "2024-05-17T19:20:46.171Z"
}
}
GET /timeline
Parameter | Type | Description |
---|---|---|
Authorization header |
string |
Required. |
Returns an object with a lists of posts
{
"message": "User timeline",
"timeline": [
{
"id": 14,
"autor": {
"id": 8,
"name": "John",
"lastName": "Endricks",
"username": "john77",
"profileImage": null
}
"content": "I love rainy days",
"date": "2024-05-23T22:12:35.151Z",
"likes": [],
"comments": []
},
{
"id": 3,
"autor": {
"id": 49,
"name": "Robert",
"lastName": "Pirez",
"username": "flowrs3",
"profileImage": null
}
"content": "Rain... Again....",
"date": "2024-05-23T22:11:50.999Z",
"likes": [],
"comments": [
{
"autorId": 2,
"content": "Yeah, I hate it!",
"date": "2024-05-23T22:11:59.999Z",
"likes": 0,
}
]
}
]
}
- Support publications with multimedia content
Server: Node, Express, TypeScript, TypeORM, SQLite