Welcome to the documentation for the Social Media API! This API is designed to handle the backend of a fictional social media platform, facilitating interactions with user data and posts. It is built using Node.js, Express, and MongoDB.
This API serves as the backend for a social media application, providing endpoints to manage users, posts (referred to as thoughts), and their interactions. It supports CRUD operations and user reactions to posts.
- Node.js
- Express.js
- MongoDB
- Mongoose
To run this project locally, follow these steps:
-
Clone the repository:
git clone <repository-url> cd <project-folder>
-
Install dependencies:
npm install
-
Start the server:
npm start
The API server will start running locally on
http://localhost:3001
.
Once the server is running, you can use a tool like Insomnia to interact with the API endpoints. Here are some of the available endpoints:
GET /api/thoughts
: Get all thoughtsPOST /api/thoughts
: Create a new thoughtGET /api/thoughts/:thoughtId
: Get a single thought by IDPUT /api/thoughts/:thoughtId
: Update a thought by IDDELETE /api/thoughts/:thoughtId
: Delete a thought by IDPOST /api/thoughts/:thoughtId/reactions
: Add a reaction to a thoughtDELETE /api/thoughts/:thoughtId/reactions
: Remove a reaction from a thought
GET /api/users
: Get all usersPOST /api/users
: Create a new userGET /api/users/:userId
: Get a single user by IDPUT /api/users/:userId
: Update a user by IDDELETE /api/users/:userId
: Delete a user by IDPOST /api/users/:userId/friends/:friendId
: Add a friend to a userDELETE /api/users/:userId/friends/:friendId
: Remove a friend from a user
Represents a thought or idea submitted by a user.
- Fields:
thoughtText
: String, requiredusername
: String, requiredcreatedAt
: Date, default: Date.nowreactions
: Array of Reaction objects
Represents a user who interacts with the application.
- Fields:
username
: String, required, uniqueemail
: String, required, unique, must be a valid emailthoughts
: Array of Thought ObjectIdsfriends
: Array of User ObjectIds
Represents a reaction or response to a thought.
- Fields:
reactionBody
: String, requiredusername
: String, requiredcreatedAt
: Date, default: Date.now
Contributions are welcome! Please feel free to submit a pull request or open issues for feature requests, bugs, or questions.
-
Fork the repository.
-
Create your feature branch:
git checkout -b feature/new-feature
. -
Commit your changes:
git commit -am 'Add new feature'
. -
Push to the branch:
git push origin feature/new-feature
. -
Submit a pull request.
Credit to Vini for letting me reverse engeneer his code to get started.
This project is licensed under the MIT License