Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

OpenFaaS Kotlin templates

This repository contains multiple Kotlin templates for OpenFaaS.

$ faas-cli template pull https://github.com/s1monw1/openfaas-kotlin
$ faas new --list

Languages available as templates:
- kotlin
- kotlin-http4k
- kotlin-quarkus-native

kotlin template

This template runs without any dependency and bootstraps its own com.sun.net.httpserver.HttpServer.

Trying the template

$ faas-cli template pull https://github.com/s1monw1/openfaas-kotlin
$ faas new --lang kotlin <fn-name>

Example usage

Example writing a successful message:

package com.openfaas.function

import com.openfaas.model.*

class Handler : IHandler {
    override fun handle(request: IRequest): IResponse {
        return Response(body = "Hello OpenFaas World")
    }
}

Example writing a custom status code

package com.openfaas.function

import com.openfaas.model.*

class Handler : IHandler {
    override fun handle(request: IRequest): IResponse {
        return Response(body = "Hello OpenFaas World", statusCode = 202)
    }
}

Example writing an error / failure.

package com.openfaas.function

import com.openfaas.model.*

class Handler : IHandler {
    override fun handle(request: IRequest): IResponse {
        return Response(body = "Error saying hello", statusCode = 500)
    }
}

The body will be written to the client along with a HTTP 500 status code.

kotlin-http4k template

This template is backed by http4k, a lightweight function http toolkit for Kotlin.

Trying the template

$ faas-cli template pull https://github.com/s1monw1/openfaas-kotlin
$ faas new --lang kotlin-http4k <fn-name>

Example usage

Example writing a successful message:

package com.openfaas.function

import org.http4k.core.*
import org.http4k.core.Status.Companion.OK

class Handler : HttpHandler {
    override fun invoke(request: Request): Response {
        return Response(OK).body("Hello OpenFaas World")
    }
}

Example writing a custom status code

import org.http4k.core.*
import org.http4k.core.Status.Companion.ACCEPTED

class Handler : HttpHandler {
    override fun invoke(request: Request): Response {
        return Response(ACCEPTED).body("Hello OpenFaas World")
    }
}

Example writing an error / failure.

import org.http4k.core.*
import org.http4k.core.Status.Companion.INTERNAL_SERVER_ERROR

class Handler : HttpHandler {
    override fun invoke(request: Request): Response {
        return Response(INTERNAL_SERVER_ERROR).body("Error saying hello")
    }
}

The body will be written to the client along with a HTTP 500 status code.

kotlin-quarkus-native template

This template is backed by Quarkus, a framework to build cloud-native JVM-based applications powered by GraalVM.

Trying the template

$ faas-cli template pull https://github.com/s1monw1/openfaas-kotlin
$ faas new --lang kotlin-quarkus-native <fn-name>

Releases

No releases published

Packages

No packages published