This is a REST API made using Node.js, Express, and MongoDB to power Image Factory- the AI generated image sharing social media platfrom I have created. The main git repo for the React Native app can be viewed here. This REST API is hosted on Heroku, and the MongoDB instance used by Image Factory is hosted on MongoDB Atlas. Watch a full demonstration of the app here.
The database stores information in the following models:
Fields: username, password, email, createdAt, updatedAt
Fields: user, followers[], following[], profilePicture, bio
Fields: image, caption, prompt, aesthetic, postedByUser, postedByUserName, likedBy[], createdAt, updatedAt
Fields: postId, userId, username, commentText, createdAt, updatedAt
Here is a brief description of the main API endpoints:
Checks a username and password combination and returns an auth token or error message to the client, depending on if the user exists and the password is correct.
Creates a new user with username, email, and password. Also creates a new UserDetails object for that user.
Finds all the users whose usernames match the search string. Produces a JSON response that contains an array with both the UserDetails and basic info for each user in the search results.
Returns the UserDetails object for a particular User.
Enables a user to follow another user by adding the appropriate users to the following and followers lists of the UserDetails objects. The request body must contain the user performing the action and the user they want to follow.
Works like the 'follow' endpoint, but removes users from the following and followers lists instead.
Updates the profile picture link (from the CDN) in the UserDetails object of the currently logged in user.
Updates the bio field of the UserDetails object of the current user.
Creates a new post in the database when a POST request is made to this endpoint with the details of the post in the request body.
Returns a JSON response to the client that contains the details of a particular post.
Returns a JSON array that contains all the posts made by a particular user.
This endpoint returns an array of posts to the client for the custom feed view of each user. The posts depend on what other users the currently logged-in user follows and are sent in reverse chronological order. This endpoint also implements pagination- the request body contains a limit for the number of posts sent to the client. As the user scrolls to the bottom of their feed, another API call is made to this endpoint with a higher limit to load more posts.
Adds the logged-in user to the likedBy[] array of the post with the specified id.
Removes the logged-in user from the likedBy[] array of the post with the specified id.
This endpoint modifies a post in the database to update various details like the post caption.
A DELETE request made to this endpoint removes a specific post from the database.
A POST request made to this endpoint with the details of the comment in the request body creates a new Comment in the database.
This endpoint can be used to get a JSON array of all the comments on a particular post specified by post_id.
The primary frameworks and libraries used in developing this API are Node.js, Express, and Mongoose. The Cloudinary CDN and API were used to handle image storage and delivery. The database for the application is MongoDB running on MongoDB Atlas, and the REST API itself is deployed on Heroku.
This application is developed by Saarthak Gupta © 2023.