wojciech-zurek / kotlin-spring-cloud-function-example

kotlin spring cloud function example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kotlin-spring-cloud-function-example

Kotlin spring cloud function example with different types of creation function, supplier and consumer. This example also contains Kotlin lambdas configured as Spring beans. There are also examples with flux - reactive type.

Download

    git clone git@github.com:wojciech-zurek/kotlin-spring-cloud-function-example.git

Run with gradle

    cd kotlin-spring-cloud-function-example/
    ./gradlew bootRun

Run as jar file

    cd kotlin-spring-cloud-function-example/
    ./gradlew bootJar
    java -jar build/libs/kotlin-spring-cloud-function-example-0.0.1-SNAPSHOT.jar

HTTP Endpoints example

/upperCase (bean, function)

    echo "Hello World" | http POST :8080/upperCase
    HTTP/1.1 200 OK
    Content-Length: 12
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    HELLO WORLD

/lowerCase (bean, function with reactive flux)

    echo "Hello World" | http POST :8080/lowerCase
    HTTP/1.1 200 OK
    Content-Length: 17
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    [
        "hello world\n"
    ]

/user (function with reactive flux)

    http POST :8080/user name=admin age=30
    HTTP/1.1 200 OK
    Content-Length: 34
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    [
        {
            "age": 30,
            "id": 0,
            "name": "admin"
        }
    ]

/log (consumer)

    echo "Message to log" | http POST :8080/log
    HTTP/1.1 200 OK
    content-length: 0

/reverse (function with reactive flux)

    echo "Message to reverse" | http POST :8080/reverse
    HTTP/1.1 200 OK
    Content-Length: 24
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    [
        "\nesrever ot egasseM"
    ]

/statistic (function)

    echo "Sample message" | http POST :8080/statistic
    HTTP/1.1 200 OK
    Content-Length: 56
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    {
        "\n": 1,
        " ": 1,
        "a": 2,
        "e": 3,
        "g": 1,
        "l": 1,
        "m": 2,
        "p": 1,
        "s": 3
    }

/unixTime (supplier)

    http :8080/unixTime  
    HTTP/1.1 200 OK
    Content-Length: 10
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    1571218287

/pi (Kotlin lambda bean, supplier)

    http :8080/pi            
    HTTP/1.1 200 OK
    Content-Length: 17
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    3.141592653589793

/square (Kotlin lambda bean, function)

    echo 12 | http :8080/square
    HTTP/1.1 200 OK
    Content-Length: 3
    Content-Type: application/json;charset=UTF-8
    accept-encoding: gzip, deflate
    connection: keep-alive
    user-agent: HTTPie/1.0.3
    
    144

/stupid (Kotlin lambda bean, consumer)

    echo "Test" | http :8080/stupid
    HTTP/1.1 200 OK
    content-length: 0

About

kotlin spring cloud function example

License:MIT License


Languages

Language:Kotlin 100.0%