Giter VIP home page Giter VIP logo

social-network-api's Introduction

social-network-api

License: MIT

Description

Task was to build an API for a social network web application where users can share their thoughts, react to friends’ thoughts, and create a friend list. The required stack includes Express.js for routing, a MongoDB database, and the Mongoose ODM. In addition to using the Express.js and Mongoose packages, I have also used a native JavaScript Date object and Web API to format timestamps.

I have created a walkthrough video that demonstrates the functionality of the API using Insomnia after creating the API. A link to the video has been provided in the README below.

Table of Contents

Installation

​Install dependencies using:

npm install

Usage

Need to have MongoDB and MongoDB Compass installed locally to run the app.

The application will then be invoked by using the following command:

npm run watch

Directory Structure

.
├── config/
├── controllers/
├── models/
│ ├── Thought.js
│ ├── User.js
│ └── index.js
├── routes/
│ ├── api/
| | ├── thoughtRoutes.js
| | ├── userRoutes.js
| | └── index.js
│ └── index.js
├── utils/
├── .gitignore
├── README.md
├── LICENSE
├── package.json
├── README.md
└── index.js

Technologies Used

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose (ODM)

Setup

  • Nodejs must be installed
  • MongoDB Compass must be installed
  • Insomnia was used to test routes
  • Text editor (VS Code recommended)

Demo

Part 1

This demos a general overview of the functionality of the api, and starts by demonstrating on how to invoke the application. I then explain how Mongoose syncs to MongoDB on server start, and go over the User and Thought models and their associated schemas and subdocuments. I also provide an brief over the getter method used to format dates, virtuals used, referenced models, self-references, and the objectId method to create a unique id value with a desired name:

Watch the video

Part 2

This demos POST User, POST Thought, POST friend, POST Reaction, GET Single User, GET Single Thought, Get All Thoughts, GET All Users. This also showcases a match validation for an incorrect email and formatted dates:

/api/users

  • GET all users
  • GET a single user by its _id and populated thought and friend data
  • POST a new user

/api/users/userId

  • PUT to update a user by its _id

/api/users/:userId/friends/:friendId

  • POST to add a new friend to a user's friend list

/api/thoughts

  • GET to get all thoughts
  • GET to get a single thought by its _id
  • POST to create a new thought (This also pushes the created thought's _id to the associated user's thoughts array field)

/api/thoughts/:thoughtId/reactions

  • POST to create a reaction stored in a single thought's reactions array field

Watch the video

Part 3

This demos PUT Thought, POST friend (second), DELETE friend:

/api/thoughts/thoughtId

  • PUT to update a thought by its _id

/api/users/:userId/friends/:friendId

  • DELETE to remove a friend from a user's friend list

Watch the video

Part 4

This demos DELETE Reaction, DELETE Thought, DELETE User (and associated thoughts):

/api/thoughts/:thoughtId/reactions

  • DELETE to pull and remove a reaction by the reaction's reactionId value

/api/thoughts/thoughtId

  • DELETE to remove a thought by its _id

/api/users/userId

  • DELETE to remove user by its _id and removes a user's associated thoughts when deleted.

Watch the video

Acknowledgements

Questions

Created by: @moedaaboul

Feel free to contact me via [email protected]!

License

This work is licensed under MIT.

social-network-api's People

Contributors

moedaaboul avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.