This project is a backend API for managing authors and their blogs. It includes schemas for authors and blogs, along with POST and GET methods to store and fetch data. MongoDB is used for data storage.
To install the necessary dependencies, use the following command:
npm install
To start the server, run:
npm start
-
POST /api/author
- Creates a new author.
- Request Body:
{ "name": "John Doe", "email": "[email protected]", "publishedDate": "2024-05-10" }
- Response:
{ "message": "Author created successfully", "author": { "_id": "609abc123def456789012345", "name": "John Doe", "email": "[email protected]", "publishedDate": "2024-05-10" } }
-
GET /api/author
- Retrieves all authors.
- Response:
[ { "_id": "609abc123def456789012345", "name": "John Doe", "email": "[email protected]", "publishedDate": "2024-05-10" }, { "_id": "609def456ghi789012345678", "name": "Jane Smith", "email": "[email protected]", "publishedDate": "2024-05-12" } ]
-
POST /api/blog
- Creates a new blog post.
- Request Body:
{ "title": "My First Blog Post", "blogContent": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "authorName": "John Doe" }
- Response:
{ "message": "Blog post created successfully", "blog": { "_id": "60abcd123456def789012345", "title": "My First Blog Post", "blogContent": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "authorName": "John Doe" } }
-
GET /api/blog
- Retrieves all blog posts.
- Response:
[ { "_id": "60abcd123456def789012345", "title": "My First Blog Post", "blogContent": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "authorName": "John Doe" }, { "_id": "60efgh456789ijk012345678", "title": "Introduction to MongoDB", "blogContent": "MongoDB is a NoSQL database.", "authorName": "Jane Smith" } ]
- JavaScript
- Node.js
- Express.js
- MongoDB
This API is created by Evita Sharon Barboza. Feel free to contribute and customize it according to your needs.