Code Monkey home page Code Monkey logo

springboot-kotlin's Introduction

Kotlin Rest API in Spring-boot, Spring-Data, H2 In-Memory DB

  • This demo project explains REST API development with Kotlin and Spring Boot.

  • Integration Tests are written using ZeroCode TDD framework

Note:
As Kotlin does the things in less code, so naturally a test framework needed to do the job in less code(almost zero code)

Kotlin gradle dependencies
	compile('com.fasterxml.jackson.module:jackson-module-kotlin')
	compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
	compile("org.jetbrains.kotlin:kotlin-reflect")

Project_Structure

Step 1: Building the Application

We will build the application to generate application jar. Integration test cases are skipped because integration tests would expect app is running, so building app first without tests, running the app and then executing integration tests.

gradle clean build -x test

or

mvn clean install -DskipTests

Gradle Build Kotlin

Step 2: Running the application

kotlin_gif3

Run from IDE (Right click and run as main):

com.xp.springboot.kotlin.SpringBootKotlinRestApiApplication

-or-

Open a new git bash and go to the build/libs folder for gadle or /target folder for maven. Run below command to run the application

java -jar SpringBootKotlinRestAPI-0.0.1-SNAPSHOT.jar

Verify the application by accessing below url directly from browser http://localhost:5000/parkrun/

Verify app running

Step 3: How to Run Integration Test Cases?

Running the gradle task named "integrationTests". This will run all the test cases defined under this gradle task.

gradle integrationTests or

mvn surefire:test

kotlin_testing_gif

Gradle Test Run

Where is the Integration Test Report?

Integration Test report and logs are generated under folder /target/

Test Report

Test Report Dashboard

Explore other end points

GET - http://localhost:5000/parkrun/runners

POST - http://localhost:5000/parkrun/runners

Sample request body:

 {
        "firstName": "Andy",
        "lastName": "Tey",
        "gender": "M",
        "runningClub": "Swindon"
 }

GET - http://localhost:5000/parkrun/runners/2

DELETE - http://localhost:5000/parkrun/runners/2

A POSt call sample looks like below-

url:http://localhost:5000/parkrun/runners
method:POST

request:
{
  "headers" : {
    "Accept" : "application/hal+json;charset=UTF-8"
  },
  "body" : {
    "firstName" : "Andy",
    "lastName" : "Terris",
    "gender" : "M",
    "runningClub" : "Nanwitch"
  }
} 

Response:
{
  "status" : 201,
  "headers" : {
    "Date" : [ "Fri, 16 Nov 2018 15:27:55 GMT" ],
    "Transfer-Encoding" : [ "chunked" ],
    "Location" : [ "http://localhost:8080/parkrun/runners/5" ],
    "Content-Type" : [ "application/hal+json;charset=UTF-8" ]
  },
  "body" : {
    "firstName" : "Andy",
    "lastName" : "Terris",
    "gender" : "M",
    "runningClub" : "Nanwitch",
    "totalRuns" : "0",
    "_links" : {
      "self" : {
        "href" : "http://localhost:8080/parkrun/runners/5"
      },
      "parkRunner" : {
        "href" : "http://localhost:8080/parkrun/runners/5"
      }
    }
  }
}

Find detailed explanation on

springboot-kotlin's People

Contributors

authorjapps avatar bethecodewithyou avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.