This is a simple RESTful API for a personal blogging platform built using Express.js and MongoDB. The API allows users to perform CRUD operations on blog posts.
- Create a new blog post
- Read a single blog post or all blog posts
- Update an existing blog post
- Delete an existing blog post
- Filter blog posts by a search term
- Node.js
- Express.js
- MongoDB
- Mongoose
- Node.js installed on your machine
- MongoDB installed or access to a MongoDB database
-
Clone the repository:
git clone https://github.com/yourusername/blog-api.git -
Navigate to the project directory:
cd blog-api -
Install the dependencies:
npm install
- Set up your MongoDB connection in
src/config/database.js. - Update any necessary environment variables.
To start the server, run:
npm start
The server will run on http://localhost:3000.
- POST
/api/posts - Request Body:
{ "title": "Post Title", "content": "Post Content", "author": "Author Name" }
- GET
/api/posts/:id
- GET
/api/posts
- PUT
/api/posts/:id - Request Body:
{ "title": "Updated Title", "content": "Updated Content" }
- DELETE
/api/posts/:id
- GET
/api/posts/search?term=searchTerm
The API includes error handling middleware to manage errors and send appropriate HTTP responses.
This project is licensed under the MIT License.