Simple Restful CRUD API for Blog for POC or demo
- Spring Boot
- Spring Rest
- Spring Data
- MySQL database for persistent
- Java - 1.8.x
- Maven - 3.x.x
- MySQL - 5.x.x
- clone this project into your local directory:
git clone https://github.com/youngInnovator/Blog-RestAPI.git
In order to achieve persistence this project relies on MySQL.
MySQL version 5.6 or better. If you have Docker installed it might be useful to run the database as a container.
Create the database for MySQL using following steps.
mysql> create database db_blog; -- Create the new database
mysql> create user 'blog'@'localhost' identified by 'blog'; -- Creates the user
mysql> grant all on db_example.* to 'blog'@'localhost'; -- Gives all the privileges to the new user on the newly created database- open
src/main/resources/application.properties - change
spring.datasource.usernameandspring.datasource.passwordas per your MySQL installation (if required)
- Build the project:
mvn clean install
- Run the
blogproject:
java -jar blog-0.0.1-SNAPSHOT.jar
Alternatively, you can run the app without packaging it using -
mvn spring-boot:run
The app will start running at http://localhost:8080.
mvn test
The app defines following CRUD APIs.
- Get all posts
GET /blog/post/
- Get specific post
GET /blog/post/{postId}
- Add new post
POST /blog/post/
- Update existing post
PUT /blog/post/
- Delete specific post
DELETE /blog/post/{postId}
- Get specific post comments
GET /blog/post/{postId}/comments
- Add new comment to specific post
POST /blog/post/{postId}/comment
- Get specific comment
GET /blog/comment/{commentId}
- Like specific comment
POST /blog/comment/{commentId}/like
- Update existing comment
PUT /blog/comment/
- Delete specific comment
DELETE /blog/comment/{postId}