This is a simple API for managing blogs and users. It allows users to create, publish, and manage their blogs. Users can also view published blogs, search for blogs, and edit their own blogs.
- User Authentication: Users can sign up, sign in, and authenticate using JWT (JSON Web Tokens) for secure access to the API endpoints.
- Blog Management: Users can create new blogs, edit their own blogs, and publish them.
- Blog Listing: Users and non-logged-in visitors can view lists of published blogs. The list is paginated and can be filtered, searched, and sorted by various criteria.
- Blog Viewing: Users and visitors can view individual published blogs. The
read_count
of the blog is updated each time it is viewed. - User-specific Actions: Users can view a list of their own blogs, edit their own blogs, and view drafts.
- Reading Time Calculation: The API estimates the reading time for each blog post based on average reading speed.
- Node.js installed on your system. You can download it from nodejs.org.
- MongoDB database to store blog and user data.
-
Clone the repository:
git clone <repository-url>
-
Install dependencies:
cd blogging-api
npm install
-
Set up environment variables:
Create a
.env
file in the project root and add the following variables:PORT=3000
MONGODB_URI=<your-mongodb-uri>
JWT_SECRET=<your-secret-key>
Replace
<your-mongodb-uri>
with the connection URI for your MongoDB database and<your-secret-key>
with a secret key for JWT authentication. -
Start the server:
npm start
POST /signup
: Create a new user account.POST /signin
: Sign in and generate JWT token for authentication.
POST /blogs
: Create a new blog (requires authentication).PUT /blogs/:id
: Edit an existing blog (requires authentication and ownership).DELETE /blogs/:id
: Delete a blog (requires authentication and ownership).
GET /blogs
: Get a list of published blogs (paginated, searchable, filterable, and orderable).GET /my-blogs
: Get a list of user's own blogs (paginated, filterable by state).GET /blogs/:id
: Get a specific published blog with the author's information.
GET /blogs/edit/:id
: Get a specific blog for editing (requires authentication and ownership).
- User Authentication:
- Use
POST /signup
to create a new user account by providingfirst_name
,last_name
,email
,username
, andpassword
. - Use
POST /signin
to sign in with youremail
andpassword
and obtain a JWT token for authentication.
- Blog Management:
- Use
POST /blogs
to create a new blog. Providetitle
,description
,tags
, andbody
in the request body. The blog will be in draft state by default. - Use
PUT /blogs/:id
to edit an existing blog. Providetitle
,description
,tags
, andbody
in the request body. Only the owner can edit the blog. - Use
DELETE /blogs/:id
to delete a blog. Only the owner can delete the blog.
- Blog Listing and Viewing:
- Use
GET /blogs
to get a list of published blogs. You can filter, search, sort, and paginate the results. - Use
GET /my-blogs
to get a list of your own blogs. You can filter by state and paginate the results. - Use
GET /blogs/:id
to view a specific published blog with the author's information. - Use
GET /blogs/edit/:id
to get a specific blog for editing. Only the owner can access this endpoint.