org.http4k.servlet.HttpHandlerServlet.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4k-core Show documentation
Show all versions of http4k-core Show documentation
Dependency-lite Server as a Function in pure Kotlin
package org.http4k.servlet
import org.http4k.core.HttpHandler
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
/**
* Simple servlet which wraps an http4k HttpHandler
*/
class HttpHandlerServlet(handler: HttpHandler) : HttpServlet() {
private val adapter = Http4kServletAdapter(handler)
override fun service(req: HttpServletRequest, resp: HttpServletResponse) = adapter.handle(req, resp)
}
fun HttpHandler.asServlet() = HttpHandlerServlet(this)