A simple API for managing blogs, including features like user management, blog creation, and administrative controls.
https://blog-project-71.vercel.app/
-
User Management
- User registration and login.
-
Blog Management
- Create, update, delete blogs.
- Public API to fetch blogs with search, filter, and sort options.
-
Admin Actions
- Admin can block a user by updating the
isBlocked
property totrue
. - Admin can delete any blog by its ID.
- Admin can block a user by updating the
GET /api/blogs
Fetches all blogs with options for searching, sorting, and filtering.
- Query Parameters:
search
: Filter blogs by title or content.sortBy
: Field to sort by (e.g.,createdAt
).sortOrder
: Sorting order (asc
ordesc
).filter
: Filter by author ID.
POST /api/blogs
Allows a logged-in user to create a blog.
- Request:
{
"title": "My First Blog",
"content": "This is my blog content."
}
PATCH /api/blogs/:blogId
Allows the author of a blog to update it.
DELETE /api/blogs/:id
Allows a logged-in user to delete their own blog by its ID.
PATCH /api/admin/users/:userId/block
Allows an admin to block a user.
DELETE /api/blogs/:blogId
Allows an admin to delete any blog.
-
Clone the repository:
git clone https://github.com/Sakhawat71/Blog-Project-a3.git
-
Install dependencies:
npm install
-
Set up environment variables:
DB_URI
: MongoDB connection string.ACCESS_TOKEN_SECRET
: Secret key for JWT.
-
Run the server:
npm start