This is a RESTful API for a blogging platform where users can write, edit, and delete blog posts. Other users can read and comment on blog posts. The platform includes user roles such as admins and regular users.
- User registration and login
- CRUD operations for blog posts
- Comment system for blog posts
- User roles and permissions
https://blog-api-one-pi.vercel.app/
- Register a user
Users are able to create an account.
POST /api/auth/register
- Login a user
Users are able to login.
POST /api/auth/login
- Logout a user
Users are able to logout.
POST /api/auth/logout
- Update Admin status
The user is able to switch role from between being a regular user and an admin to manage some tasks
PUT /api/users/:userId/isAdmin
- Create a post(s)
Creates a new post for the blog
POST /api/post
- Get all posts
Retrieves a list of all posts
GET /api/posts
- Get a post by id
Retrieves a post by id
GET /api/posts/:postId
- Update a post
Upadate the details of the post
PUT /api/post/:postId
- Delete a post
Delete a post
DELETE /api/posts/:postId
- Create a comment
Creates a comment under a post
POST /api/comment/create
- Get all comments
Retrieve all comments under a specific post
GET /api/comment/post/:postId"
- Get a specific comments
Retrieve a comment under a specific post using id
GET /api/comment/:commentId"
- Update a comment
Update the comment
PUT /api/comment/:commentId
- Delete a comment
Delete a comment by id
Delete /api/comment/:commentId
- Get all users
Get all users
DELETE /api/users
- Get a user
Get a user by id
DELETE /api/users/:userId
- Delete a user
Delete a user
DELETE /api/users/:userId
- Update status of user Update status from user to admin and vice versa
PUT /api/users/:userId/isAdmin
- Delete a post by a user
Delete a post
DELETE /api/posts/:postId
- Delete a comment
Delete a comment by a user under a post.
Delete /api/comment/:commentId
- Delete all comments This achieved by the admin to delete all comments under a post.
DELETE /api/comment/post/:postId
Ensure you have the following installed on your machine:
- Node.js
- npm (Node Package Manager)
- MongoDB
- Node.js
- Express.js
- MongoDB
- JWT for authentication
- Clone the repository:
git clone https://github.com/motuncoded/blog-api.git
- Navigate to the project directory:
cd blog-api
- Install dependencies:
npm install
-
Set up environment variables:
- Create a
.env
file in the root directory. - Add necessary environment variables (e.g., database connection strings).
- Create a
PORT=5002
MONGODB=your_mongodb_url
JWT_SECRET=your_secret_key
- Start the server:
npm start
Execute the following command to run tests:
npm test
Contributions are welcome! Please create an issue or submit a pull request with your improvements.
This project is licensed under the MIT License.