This project is built with Express and Mongoose. It has various API endpoints for authentication, users, recipes, categories, and subcategories. JWT tokens are managed via cookies and are required for many endpoints. All responses are returned in JSON format.
-
Clone the repository
git clone <repo-url> -
Install dependencies
npm install -
Create a .env file with the following variables:
PORTMONGODB_URIJWT_SECRETNODE_ENV
-
Start the server
npm start
- What it does: Registers a new user.
- Required fields:
username(string)email(string)password(string)name(string)surname(string)
- Response: Returns a
SIGNUP_SUCCESSmessage and sets a JWT cookie.
- What it does: Logs in a user.
- Required fields:
email(string)password(string)
- Response: Returns a
LOGIN_SUCCESSmessage and sets a JWT cookie.
- What it does: Logs out the user.
- Response: Returns a
LOGOUT_SUCCESSmessage.
- What it does: Retrieves the current logged-in user’s information.
- Requires: A valid JWT cookie.
- Response: Returns the user object.
- What it does: Updates the current user's profile.
- Expected data:
username,name,surname,dob,profileImage,gender,bio,links
- Response: Returns a
USER_UPDATEDmessage.
- What it does: Retrieves a user by ID.
- Response: Returns the user object.
- What it does: Lists the followers of a user.
- Response: Returns an array of followers.
- What it does: Lists the users that the specified user is following.
- Response: Returns an array of followings.
- What it does: Follows the specified user.
- Requires: A valid JWT cookie.
- Response: Returns a
USER_FOLLOWEDmessage.
- What it does: Unfollows the specified user.
- Response: Returns a
USER_UNFOLLOWEDmessage.
- What it does: Retrieves a list of recipes.
- Query Parameters:
page,limit,search,category,sub_category,author,cooking_devices,difficultypreparing_time_min/max,cooking_time_min/maxnutrition_calories_min/max, etc.
- Response: Returns a list of recipes along with meta data (current page, total pages, etc.).
- What it does: Creates a new recipe.
- Requires: A valid JWT cookie (user must be logged in).
- Required fields:
titlecooking_devices(array)servingspreparing_time,cooking_timedescription(optional)nutrition(includes calories, protein, fat, carbs)image_url,video,gallerycategory,sub_category
- Additionally:
components(array)informations(array)instructions(array)
- Response: Returns a
RECIPE_CREATEDmessage and the newly created recipe object.
- What it does: Retrieves the details of a recipe by its ID.
- Response: Returns the recipe object with populated fields.
- What it does: Updates an existing recipe.
- Requires: A valid JWT cookie and the user must be the owner of the recipe.
- Expected data: Updated recipe fields.
- Response: Returns a
RECIPE_UPDATEDmessage.
- What it does: Deletes a recipe.
- Requires: A valid JWT cookie and the user must be the owner of the recipe.
- Response: Returns a
RECIPE_DELETEDmessage.
- What it does: Retrieves a recipe by user ID and its slug.
- Response: Returns the recipe object.
Components:
- POST
/recipes/:recipe_id/components- Adds a new component.
- PUT
/recipes/:recipe_id/components/:component_id- Updates a component.
- DELETE
/recipes/:recipe_id/components/:component_id- Deletes a component.
Informations:
- POST
/recipes/:recipe_id/informations- Adds additional information.
- PUT
/recipes/:recipe_id/informations/:information_id- Updates the information.
- DELETE
/recipes/:recipe_id/informations/:information_id- Deletes the information.
Instructions:
- POST
/recipes/:recipe_id/instructions- Adds an instruction.
- PUT
/recipes/:recipe_id/instructions/:instruction_id- Updates an instruction.
- DELETE
/recipes/:recipe_id/instructions/:instruction_id- Deletes an instruction.
Comments & Replies:
- POST
/recipes/:recipe_id/comments- Adds a comment.
- PUT
/recipes/:recipe_id/comments/:comment_id- Updates a comment.
- DELETE
/recipes/:recipe_id/comments/:comment_id- Deletes a comment.
- POST
/recipes/:recipe_id/comments/:comment_id/replies- Adds a reply to a comment.
- PUT
/recipes/:recipe_id/comments/:comment_id/replies/:reply_id- Updates a reply.
- DELETE
/recipes/:recipe_id/comments/:comment_id/replies/:reply_id- Deletes a reply.
Rating:
- POST
/recipes/:recipe_id/rate- Rates the recipe.
- GET
/recipes/:recipe_id/my-rating- Retrieves the user's rating for the recipe.
Bookmark:
- GET
/recipes/:recipe_id/my-bookmark- Checks if the recipe is bookmarked by the user.
- POST
/recipes/:recipe_id/bookmark- Toggles the bookmark for the recipe.
- What it does: Retrieves all categories.
- Response: Returns an array of categories.
- What it does: Creates a new category.
- Requires: A valid JWT cookie.
- Required fields:
name(mandatory)description(optional)imageUrl(optional)
- Response: Returns a
CATEGORY_CREATEDmessage.
- What it does: Retrieves a category by its ID.
- Response: Returns the category object.
- What it does: Deletes a category.
- Requires: A valid JWT cookie.
- Response: Returns a
CATEGORY_DELETEDmessage.
- What it does: Retrieves a category by its slug.
- Response: Returns the category object.
- What it does: Retrieves subcategories for a given category ID.
- Response: Returns an array of subcategories.
- What it does: Retrieves subcategories for a category using its slug.
- Response: Returns an array of subcategories.
- What it does: Updates a category.
- Requires: A valid JWT cookie.
- Expected data: Updated category fields.
- Response: Returns a
CATEGORY_UPDATEDmessage.
- What it does: Retrieves all subcategories.
- Response: Returns an array of subcategories.
- What it does: Creates a new subcategory.
- Requires: A valid JWT cookie.
- Required fields:
namedescriptionimage_urlcategory_id
- Response: Returns a
SUBCATEGORY_CREATEDmessage.
- What it does: Retrieves a subcategory by its ID.
- Response: Returns the subcategory object.
- What it does: Deletes a subcategory.
Note: The parameter name might sometimes be "subcatagory_id". - Requires: A valid JWT cookie.
- Response: Returns a
SUBCATEGORY_DELETEDmessage.
- What it does: Updates a subcategory.
- Requires: A valid JWT cookie.
- Expected data: Updated subcategory fields.
- Response: Returns a
SUBCATEGORY_UPDATEDmessage.
- What it does: Retrieves a subcategory by its slug.
- Response: Returns the subcategory object.
- All error responses are returned in JSON format.
- The error object includes an
error.codeanderror.message. - Error codes and messages are fetched from a texts.json file.
- Protected endpoints require a valid JWT cookie.
- Input data is validated via middleware.
- User roles can be enforced with role-check middleware (checkRoles).
- All sent data must be in the correct format.
- Query parameters and request bodies are validated.
- Some endpoints use transactions (Mongoose sessions) for data integrity.
MIT
This documentation serves as a basic reference for using the API. Example requests and responses can be tested using your preferred API testing tool.
Happy coding!