A boilerplate for a social network API. It provides basic CRUD functionality to manage Users, Thoughts, Reactions. I used MongoDB as a backend datastore and Mongoose for ODM. The structure of the codebase loosely follows MVC design pattern.
NOTE: Make sure you have
Node.JS ~v16.14.2andNPM ~8.11.0installed. You can quickly check this by runningnode -vfor Node.JS andnpm -vfor NPM in your terminal.
Once the above is confirmed, go ahead and clone the repo git clone git@github.com:rkutsel/social-network-api.git and install local dependencies by running npm install in your terminal. A successful installation should look somewhat similar to the one bellow:
added 202 packages, and audited 203 packages in 1s
27 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilitiesTo start the API server, form the root directory run node index or npm start which should fire up all of the components. Optionally you can run npm run dev for better dev experience. At this point you should be able to consume the API. You can use any API client. For the purpose of this example, I used Insomnia Client that has a free version.
User Model:
-
username- String
- Unique
- Required
- Trimmed
-
email- String
- Required
- Unique
- Must match a valid email address. Email validator.
-
thoughts- Array of
_idvalues referencing theThoughtmodel
- Array of
-
friends- Array of
_idvalues referencing theUsermodel (self-reference)
- Array of
Thought Model:
-
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(The user that created this thought)- String
- Required
-
reactions- Array of nested documents created with the
reactionSchema
- Array of nested documents created with the
Reaction (SCHEMA ONLY)
-
reactionId- Mongoose's ObjectId data type
- Default value is set to a new ObjectId
-
reactionBody- String
- Required
- 280 character maximum
-
username- String
- Required
-
createdAt- Date
- Default value to the current timestamp
- Getter method to format the timestamp on query
/api/users
-
GETall users -
GETa single user by its_idand populated thought and friend data -
POSTa new user: -
PUTto update a user by its_id -
DELETEto remove user by its_idalong with associated thoughts.
/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) -
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



