Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aniraannu/social-network-api
https://github.com/aniraannu/social-network-api
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/aniraannu/social-network-api
- Owner: aniraannu
- License: mit
- Created: 2024-08-25T03:33:27.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-17T19:24:31.000Z (4 months ago)
- Last Synced: 2024-09-17T23:43:42.924Z (4 months ago)
- Language: JavaScript
- Size: 16.7 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Social Network API
This API allows users to create and manage a social network with features like creating profiles, creating posts, commenting on posts, and following other users. The API is built using NoSQL technologies and JavaScript.
## Description
This application is an API for a social network web application where users can share their thoughts, react to friends’ thoughts, and create a friend list.This backend app that can be used for social media startups, uses a NoSQL database.It also uses Express.js for routing, and a MongoDB database. The Mongoose ODM is used to handle large amounts of unstructured data, including User and Thought models and schemas. We also made use of a subdocument in thoughts model . When the application is invoked, the server is started and Mongoose models are synced to the MongoDB database.
By using API GET routes in Insomnia Core for users and thoughts we can retrive the data from the database in the form of JSON. API POST, PUT, and DELETE routes in Insomnia Core successfully create, update, and delete users and thoughts in the database. API POST and DELETE routes is used to create and delete reactions to thoughts and add and remove friends to a user’s friend list.
The following animation demonstrates the application functionality:https://drive.google.com/file/d/1X_uVoQi05VWe6kVfsbPFnzza2DaLNsvK/view?usp=sharing
## Getting Started
- This is a social network API that uses MongoDB, a NoSQL database, which allows the website to handle large amounts of unstructured data.When the command to invoke the application is entered, the Mongoose models are synced to the MongoDB database.
- When API GET routes for users and thoughts are opened in Insomnia, the data for each of the routes is displayed in formatted JSON. User, Friend, Thought, and Reaction routes are created to create the database and test the API on Insomnia.
1. User Routes:
A user can create a user with a username and valid email address. When created, each user is assigned a unique user ID.To create a user, click the POST request and enter the user's username and email address. Click Send. There are two GET requests that return user information. To return all users, click the Find All Users request, then click on Send. To return a single user, click the Find User by Id request. On the URL, enter the user's ID.
![Create a new user](./Assets/images/create-newuser.png)
![Get All users](./Assets/images/get-all-users.png)
![Get a single user by ID](./Assets/images/get%20a%20single%20user%20by%20id.png)To update a user by ID, click the PUT request. On the URL, enter the ID of the user whose information is going to be updated. To delete a user by ID, click the DELETE request and enter the user's ID. A message that reads, "User and thoughts deleted!" will appear if the user has been deleted from the database. If there is no such user or user ID in the system, the message, "No user with this id!" is shown. Click Find All Users to see if the user has been deleted. The thoughts assosiated with the user will also be deleted along with user.
![Update a user](./Assets/images/update-user.png)
![Remove a user](./Assets/images/remove-a-user.png)2. Friend Routes:
A user can add a friend and delete a friend.To add a friend, click the POST request. On the URL enter the user ID of the user who is adding a friend, then the user ID of the friend the user is adding. To see the user's friends, click Find All Users. The ID of the friends the user added are listed under "friends". The "friendCount" indicates the number of friends the user added.
![Add a friend to a user](./Assets/images/Add-a-friend.png)To remove or delete a friend, click the DELETE request. On the URL enter the user ID of the user who is deleting a friend, then the user ID of the friend the user is deleting.To check if the friend has been removed from the user's friend list, click Find All Users.
![Remove a friend](./Assets/images/Remove-a-friend.png)3. Thought Routes:
A user can create a thought, get all thoughts or a single thought by ID, update a thought by ID, and delete a thought by ID. To create or add a thought, click the POST request. Enter the "thoughtText", "username", "userID" of the user creating the thought. To get all thoughts, click the GET All Thoughts request. All the thoughts that were created will appear, as well as the date and time they were created. Each created thought is assigned a unique thought ID. Click GET All Users to access the thought ID.
![Create a thought](./Assets/images/create-a-thought.png)
![Get all thoughts](./Assets/images/get-all-thoughts.png)
![Get a single thought by ID](./Assets/images/get-a-single-thoughts-by-ID.png)To get a thought by ID, click the GET Thought by Id request and enter the thought ID. To update a thought, click the PUT request. On the URL, enter the thought ID. Enter the necessary changes on the text body. To see the changes, click GET All Thoughts.
![Update a thought by ID](./Assets/images/update-a-thought-by-ID.png)To delete a thought by ID, click the DELETE request. On the URL, enter the thought ID that will be deleted. When the thought is successfully deleted, the text can no longer be found when you try to access it by clicking GET All Thoughts. The thought ID is also deleted when you click Find All Users.
![Remove a thought by ID](./Assets/images/delete-a-thought-by-id.png)4. Reaction Routes:
A user can create a reaction and delete a reaction.To create a reaction, click the POST request. On the URL, enter the ID of the thought the user is reacting or commenting on. Then enter the "reactionBody" and "username" of the user creating the reaction. Click on GET All Thoughtsto see the reaction, the username of the user who created the reaction, the reaction ID, date and time the reaction is created, and the user's reaction count.
![Add a review](./Assets/images/Add-a-reaction.png)To delete a reaction, click the DELETE request. On the URL, enter the ID of the thought the user created a reaction or commented on, then the reaction ID.The message, "No thought with this id!" will appear when a reaction is deleted or a reaction is not associated with a user ID.
![Delete a review](./Assets/images/remove-reaction.png)MongoDB - After creating data on Insomnia, MongoDB also reflects the same data and changes that were made. The whole workflow of the application is shown in the following video:https://drive.google.com/file/d/1X_uVoQi05VWe6kVfsbPFnzza2DaLNsvK/view?usp=sharing
### Dependencies
- express 4.19.2
- mongoose 8.5.4
- nodemon 3.1.4### Installing
- Clone the repo: git clone https://github.com/aniraannu/social-network-API
- Open in VS Code. If you do not have VS code you must install it.
- Using the terminal, install node.js v16. If you have homebrew, the command should look like the following (brew install node@16), however this may vary and the documentation should be consulted.
- Once node.js v16 is installed, in the terminal, utilize the command npm init -y to initialize and create a package.json where project files will be stored.
- Next, use the terminal to run the command npm i to install the dependencies associated with this application.Node.js and MongoDB is required to run the application
- To run the application, within the terminal, type the command node index.js.
### Executing program
- The application code can be cloned from the following Github link:
[GitHub-social-network-API](https://github.com/aniraannu/social-network-API)## Help
NA
## Authors
Contributors names and contact info
Anira Raveendran
[@aniraannu](https://github.com/aniraannu)## Version History
- 0.1
- Initial Release## License
None
## Acknowledgments
Inspiration, code snippets, etc.
- [dbader](https://github.com/dbader/readme-template)
- [stackflow](https://stackoverflow.com/)
- [chatGPT](https://chatgpt.com/)