An API created with Express.js, MongoDB, and the Mongoose npm module. Users, Thoughts, and Reactions are the three main data models that the API is intended to help manage. Developers can conduct necessary CRUD (Create, Read, Update, Delete) actions on the data thanks to the extensive set of routes it provides.
- Key Features 🔑
- Installation 🛠️
- Usage 📘
- Contributing 🤝
- Tests 🧪
- License 📜
- Credits 🙏
- Questions ❓
Express.js Framework: By utilizing the strength of Express.js, this API offers quick and effective middleware and routing capabilities.
MongoDB Database: To store and retrieve data quickly, the API effortlessly connects with MongoDB, a dependable NoSQL database.
Mongoose npm Library: Mongoose streamlines interaction with MongoDB by making data modeling and validation easier.
User, Thought, Reaction Model: The API comes with User and Thought models that make it possible to create, retrieve, update, and delete user and thoughts data. The Reaction model provides a complete solution for handling reactions to thoughts and allows developers to interact with reactions.
HTTP Methods: The API offers developers a flexible and comprehensive set of HTTP methods, including GET, PUT, POST, and DELETE.
To install the necessary dependencies, run the following command:
npm i
npm install express@4.17.1
npm install mongoose@7.0.2
Install DevDependency for developing purposes:
npm install nodemon@2.0.3
- Clone the repository to your local system.
- Install dependencies to the project directory and typing npm install to get everything set up.
- Make sure you have a MongoDB instance running locally or on a remote server before setting up MongoDB. Set up the connection information as necessary in your application code.
- Run the application by using a process manager
node server.js
to start the Express.js server. - Explore the API: By sending HTTP queries to the specified routes, you can now explore the API.
/api/users
GET
all usersPOST
a new user:
// example data
{
"username": "lernantino",
"email": "lernantino@gmail.com"
}
/api/users/:userId
GET
a single user by its_id
and populated thought and friend dataPUT
to update a user by its_id
DELETE
to remove user by its_id
/api/users/:userId/friends/:friendId
POST
to add a new friend to a user's friend listDELETE
to remove a friend from a user's friend list
/api/thoughts
GET
to get all thoughtsPOST
to create a new thought
// example data
{
"thoughtText": "Here's a cool thought...",
"username": "lernantino",
}
/api/thoughts/:thoughtId
GET
to get a single thought by its_id
PUT
to update a thought by its_id
DELETE
to remove a thought by its_id
/api/thoughts/:thoughtId/reactions
POST
to create a reaction stored in a single thought'sreactions
array field
/api/thoughts/:thoughtId/reactions/:reactionId
DELETE
to pull and remove a reaction by the reaction'sreactionId
value
Contributions to this API project are welcome. If you encounter issues, have suggestions for improvements, or would like to contribute, please open an issue or submit a pull request.
To run tests, users can install insomnia and run HTTP requests. Please refer to the usage section.
This project is licensed under The MIT License. Here is the link to the license to access more information for your reference: https://opensource.org/licenses/MIT
I utilized the study material provided by the institution as a reference to complete my application.
Following are the documents I used to help me write code:
- MongoDB Compass docs on Connect to MongoDB
- MongoDB Compass docs on Embedded MongoDB Shell
- MongoDB docs on Creating a MongoDB Database with the CLI (the MongoDB shell)
- MongoDB docs on MongoDB CRUD Operations
- MongoDB Compass docs on View Documents
- MongoDB Compass docs on Modify Documents
- Official MongoDB Node Driver docs on Connecting to Database
- MongoDB docs on Find a Document
- MongoDB docs on Insert a Document
- MongoDB docs on Sort
- MongoDB docs on Skip
- MongoDB docs on Limit
- Mongoose docs on models
- Mongoose docs on schemas
- Mongoose docs on validation
- Mongoose docs on findOneAndUpdate()
- Mongoose docs on subdocuments
- Mongoose docs on constructing models
- How can we use the
ObjectId
to ensure we are able to query a student based on the value in their_id
field? - deploy-with-heroku-and-mongodb-atlas
If you have further questions, you are welcome to reach me through my email at hazkeel27@gmail.com.
You can view my projects by going through my GitHub profile at https://github.com/hazkeel27.