A simple RESTful API for managing blog posts built with Node.js, Express, and MongoDB. This API allows users to create, view, edit, and delete blog posts.
- Create Post: Users can add a new blog post with a title and content.
- View All Posts: Users can browse a list of all available blog posts, displayed in reverse chronological order.
- View Post Details: Users can click on a blog post to view the full content and see the date it was posted.
- Edit Post: Users can modify an existing post's title and content.
- Delete Post: Users can remove a blog post from the list.
- Node.js
- Express.js
- MongoDB
- Mongoose
- dotenv
- Body-Parser
- Node.js (v12 or later)
- MongoDB (local or remote)
- npm (Node package manager)
git clone https://github.com/DishantMadariya/Blog-Api.git
cd blog-api
npm install
In the root of your project, create a .env
file and add your MongoDB connection string:
MONGO_URI=mongodb://localhost:27017/blogDB
PORT=6000 # Optional: Specify the port number
npm start
or, if you're using nodemon for development:
nodemon app.js
The server should now be running on http://localhost:6000
.
Method | Endpoint | Description |
---|---|---|
POST | /api/posts | Create a new blog post |
GET | /api/posts | Get all blog posts |
GET | /api/posts/:id | Get a specific blog post |
PUT | /api/posts/:id | Update a blog post |
DELETE | /api/posts/:id | Delete a blog post |
You can test the API using tools like Postman or cURL.
POST /api/posts
{
"title": "My First Post",
"content": "This is the content of the post."
}
GET /api/posts
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to contribute by opening issues or submitting pull requests.
- Inspired by various RESTful API examples and tutorials.
- Special thanks to the developers of Express and MongoDB for making this possible.