This is a RESTful API for a blogging platform. It allows users to create, read, update, and delete blog posts. Users can also like and unlike posts, and add, delete, like, and unlike comments.
This project serves as the backend for two frontend applications:
- Blog Admin: An administrative interface where all the posts can be created, updated, and deleted by the admin.
- Portfolio: A public-facing site where users can read and engage with the blog posts.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Node.js
- npm
- MongoDB
- Clone the repository:
git clone https://github.com/mosmn/blog-api.git- Install the dependencies:
npm install- Create a
.envfile in the root directory of the project and add the following environment variables:
PORT=3000
MONGODB_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret- Start the server:
npm startAll routes are prefixed with /blog.
GET /posts: Get all posts.GET /posts/:id: Get a specific post.POST /posts: Create a new post. Requires admin privileges.PUT /posts/:id: Update a specific post. Requires admin privileges.DELETE /posts/:id: Delete a specific post. Requires admin privileges.PATCH /posts/:id/like: Like a specific post.PATCH /posts/:id/unlike: Unlike a specific post.GET /posts/:id/comments: Get all comments for a specific post.POST /posts/:id/comments: Add a comment to a specific post.DELETE /posts/:id/comments/:commentId: Delete a specific comment. Requires the user to be the author of the comment or an admin.PATCH /comments/:id/like: Like a specific comment.PATCH /comments/:id/unlike: Unlike a specific comment.
- Express - The web framework used
- Mongoose - Object Data Modeling (ODM) library for MongoDB and Node.js
- Passport - Authentication middleware for Node.js
- jsonwebtoken - Implementation of JSON Web Tokens
- bcryptjs - Library to hash and check passwords
This project is licensed under the ISC License.