Wednesday, December 11, 2019

Kotlin SpringBoot 2 Spring Data JPA RESTful Web Service

Hi everyone.

I share example how to integration Kotlin - Spring Boot2 - Spring Data JPA-RESTful Web Service and CRUD example.


Technologies used:

1. Spring Boot 2.2.2.RELEASE
2. Gradle 2.x
3. Java 8
4. Eclipse: Oxygen.1.a Release (4.7.1a) or  IntelliJ Community
5. Spring Tools Suite (STS) 4
6. Postman
7. MySql

Code on GitHub:

https://github.com/HenryXiloj/Kotlin-SpringBoot2-RESTful


Steps:

Step 1:

Execute next script on MySql

CREATE TABLE users 
             ( 
                          id       INT(11) NOT NULL auto_increment, 
                          username VARCHAR(255) NOT NULL, 
                          password VARCHAR(255) NOT NULL, 
                          created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() on 
             UPDATE CURRENT_TIMESTAMP(), 
                    PRIMARY KEY (id) 
             )

Step 2: Import project on Eclipse or IntelliJ


Eclipse:


IntelliJ:  File -> open --> choose folder backend




Righ click on project  Gradle -> Refresh Gracle project (Eclipse)



IntelliJ:

View -> Tool Windows -> Gradle -> Righ click on project -> Refresh Gradle dependencies



Step 3.

Run project from directory on console next command:

./gradlew bootRun



Run project from IntelliJ :

View -> Tool Windows -> Gradle -> Execute Gradle Task -> gradle bootRun




Step 4: Test.


GET  (by default)
GET all users

http://localhost:8080/ws/users





GET user by id.

http://localhost:8080/ws/users/1




POST user (save)

http://localhost:8080/ws/users





PUT user (update user)

http://localhost:8080/ws/users/1




DELETE user.

http://localhost:8080/ws/users/1



Great :).















References:








































Creating REST APIs with OpenAPI, Spring Boot 3.3.3, Java 21, and Jakarta

 Introduction In today's software landscape, designing robust and scalable REST APIs is a crucial aspect of application development. Wit...