This is a simple Blog API that allows users to create, read, update, and delete blog posts. It is built using REST API architecture and consists of two main parts: the backend API and the frontend server.
BLOGAPI/
│
├── public/
│ └── styles/
│ └── main.css
│
├── views/
│ ├── index.ejs
│ └── modify.ejs
│
├── index.js
├── package.json
└── server.js
- Clone the repository
git clone https://github.com/MercySpectures/BlogAPI.git
- Navigate into the project directory
cd blogapi
- Install the dependencies
npm install
To start the backend API server, run:
node index.js
The API server will start on http://localhost:4000
.
To start the frontend server, run:
node server.js
The frontend server will start on http://localhost:3000
.
Endpoint: POST /posts
Request Body:
{
"title": "Blog Title",
"content": "Blog Content",
"author": "Author Name"
}
Response:
{
"id": 4,
"title": "Blog Title",
"content": "Blog Content",
"author": "Author Name",
"date": "2024-06-06T00:00:00.000Z"
}
Endpoint: GET /posts
Response:
[
{
"id": 1,
"title": "The Rise of Decentralized Finance",
"content": "Content of the first blog",
"author": "Alex Thompson",
"date": "2023-08-01T10:00:00Z"
},
...
]
Endpoint: GET /posts/:id
Response:
{
"id": 1,
"title": "The Rise of Decentralized Finance",
"content": "Content of the first blog",
"author": "Alex Thompson",
"date": "2023-08-01T10:00:00Z"
}
Endpoint: PATCH /posts/:id
Request Body:
{
"title": "Updated Blog Title",
"content": "Updated Blog Content",
"author": "Updated Author"
}
Response:
{
"id": 1,
"title": "Updated Blog Title",
"content": "Updated Blog Content",
"author": "Updated Author",
"date": "2023-08-01T10:00:00Z"
}
Endpoint: DELETE /posts/:id
Response:
{
"message": "Post deleted successfully"
}
Endpoint: GET /
Fetches all posts and renders the index.ejs
view.
Endpoint: GET /new
Renders the modify.ejs
view with heading "New Post" and submit button "Create Post".
Endpoint: GET /edit/:id
Fetches a specific post by ID and renders the modify.ejs
view with heading "Edit Post" and submit button "Update Post".
Endpoint: POST /api/posts
Creates a new post and redirects to the main page.
Endpoint: POST /api/posts/:id
Partially updates a post by ID and redirects to the main page.
Endpoint: GET /api/posts/delete/:id
Deletes a post by ID and redirects to the main page.
- index.ejs: Displays the list of all blog posts.
- modify.ejs: Provides a form to create or edit a blog post.
- main.css: Contains the CSS styles for the project, located in
public/styles/
.
This project is licensed under the MIT License - see the LICENSE file for details.