For this project I built an API for a social network using Express.js for routing, a MongoDB database, and the Mongoose ODM.
AS A social media startup
I WANT an API for my social network that uses a NoSQL database
SO THAT my website can handle large amounts of unstructured dataThe following animations show examples of the application's API routes being tested in Insomnia.
The first animation shows GET routes to return all users and all thoughts being tested in Insomnia:
The second animation shows GET routes to return a single user and a single thought being tested in Insomnia:
The third animation shows the POST, PUT, and DELETE routes for users being tested in Insomnia:
Your walkthrough video should also show the POST, PUT, and DELETE routes for thoughts being tested in Insomnia.
The final animation shows the POST and DELETE routes for a user’s friend list being tested in Insomnia:
User
-
username- String
- Unique
- Required
- Trimmed
-
email- String
- Required
- Unique
- Must match a valid email address (look into Mongoose's matching validation)
-
thoughts- Array of
_idvalues referencing theThoughtmodel
- Array of
-
friends- Array of
_idvalues referencing theUsermodel (self-reference)
- Array of
Schema Settings
Create a virtual called friendCount that retrieves the length of the user's friends array field on query
Thought
-
thoughtText- String
- Required
- Must be between 1 and 280 characters
-
createdAt- Date
- Set default value to the current timestamp
- Use a getter method to format the timestamp on query
-
username- Which user created this thought- String
- Required
-
reactions(like replies)- Array of nested documents created with the
reactionSchema
- Array of nested documents created with the
Schema Settings
Create a virtual called reactionCount that retrieves the length of the thought's reactions array field on query
Reaction (SCHEMA ONLY)
-
reactionId- Use Mongoose's ObjectId data type
- Default value is set to a new ObjectId
-
reactionBody- String
- Required
- 280 character maximum
-
username- String
- Required
-
createdAt- Date
- Set default value to the current timestamp
- Use a getter method to format the timestamp on query
Schema Settings
This will not be a model, but rather used as the reaction field's subdocument schema in the Thought model.
/api/users
-
GETall users -
GETa single user by its_idand populated thought and friend data -
POSTa new user:
// example data
{
"username": "patrick",
"email": "patrick@gmail.com"
}-
PUTto update a user by its_id -
DELETEto remove user by its_id
/api/users/:userId/friends/:friendId
-
POSTto add a new friend to a user's friend list -
DELETEto remove a friend from a user's friend list
/api/thoughts
-
GETto get all thoughts -
GETto get a single thought by its_id -
POSTto create a new thought (don't forget to push the created thought's_idto the associated user'sthoughtsarray field)
// example data
{
"thoughtText": "Here's a cool thought...",
"username": "lernantino",
"userId": "5edff358a0fcb779aa7b118b"
}-
PUTto update a thought by its_id -
DELETEto remove a thought by its_id
/api/thoughts/:thoughtId/reactions
-
POSTto create a reaction stored in a single thought'sreactionsarray field -
DELETEto pull and remove a reaction by the reaction'sreactionIdvalue
- Patrick Ciongoli
- patrick.ciongoli@gmail.com
Thanks for viewing!



