Blog Application to create, read, update, and delete blog posts.
Before running this Spring project, make sure you have the following prerequisites installed:
- Java Development Kit (JDK) 17 or higher
- Apache Maven
- MongoDB
To install and run the Blogapp project, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/Blogapp.git
-
Navigate to the project directory:
cd Blogapp cd blogsite
-
Build the project using Maven:
mvn clean install
-
Configure the database connection in the
application.properties
file:spring.data.mongodb.uri=mongodb://localhost:27017/BlogModelDB
-
Start the mongoDB sever:
mongosh
-
Setup the database:
use BlogModelDB
-
Run the application:
mvn spring-boot:run
Once the application is running, you can access it at http://localhost:8080
in your web browser. From there, you can create, read, update, and delete blog posts.
To create a new blog post, send a POST request to the /blogs
endpoint with the following JSON payload:
{
"author":"Author Name",
"title": "New Blog Post",
"content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
}
The server will respond with the newly created blog post object, including its unique identifier.
To fetch all blog posts, send a GET request to the /blogs
endpoint. The server will respond with a list of all blog posts available in the application.
Example response:
[
{
"id": "1",
"author": "Author Name",
"title": "First Blog Post",
"content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
},
{
"id": "2",
"author": "Author Name",
"title": "Second Blog Post",
"content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
},
...
]
You can use this response to display a list of all blog posts on your application's frontend.
To retrieve a specific blog post, send a GET request to the /blogs{posId}
endpoint, where {postId}
is the unique identifier of the desired blog post.
The server will respond with the blog post object, including its title, content, and other details.
To update an existing blog post, send a PUT request to the /blogs/{postId}
endpoint, where {postId}
is the unique identifier of the blog post to be updated. Include the updated content in the JSON payload:
{
"id":"1",
"author":"Author Name",
"title": "Updated Blog Post",
"content": "New content for the blog post."
}
The server will respond with the updated blog post object.
To delete a blog post, send a DELETE request to the /blogs/{postId}
endpoint, where {postId}
is the unique identifier of the blog post to be deleted.
The server will respond with a success message indicating that the blog post has been deleted.