Blog API is a RESTful web service developed using Spring Boot, allowing users to interact with a Blog Engine that includes posts. The API does not include authentication and can handle titles and bodies for each post.
This is backend behaves the same as the Ruby on Rails Blog Api, just wanted to create the same on a different technology stack.
- Java
- Spring Boot
- PostgreSQL
- Maven
- JUnit
- Mockito
- Java 8 or higher
- PostgreSQL
- Maven
-
Clone the Repository
git clone https://github.com/alexertech/blog_api_spring.git cd blog_api_spring
-
Set Up the Database
- Install PostgreSQL if not already installed.
- Create a new database named
blog_api_spring
. - Update the
application.properties
file with your PostgreSQL username and password.
spring.datasource.username=<your-username> spring.datasource.password=<your-password>
-
Build and Run the Application
./mvnw clean install ./mvnw spring-boot:run
curl -X GET http://localhost:8080/posts
curl -X GET http://localhost:8080/posts/{postId}
curl -X POST -H "Content-Type: application/json" -d '{"title": "Post Title", "body": "Post Body"}' http://localhost:8080/posts
curl -X PUT -H "Content-Type: application/json" -d '{"title": "Updated Title", "body": "Updated Body"}' http://localhost:8080/posts/{postId}
curl -X DELETE http://localhost:8080/posts/{postId}
To run the tests, execute the following command in the project directory.
./mvnw test