Home

The Hexagon toolkit is meant to provide abstraction from underlying technologies (data storage, HTTP server engines, etc.) to be able to change them with minimum impact.

It is designed to fit in applications that conforms to the Hexagonal Architecture (also called Clean Architecture or Ports and Adapters Architecture).

Hello World

Simple Hello World HTTP example.

import com.hexagonkt.http.httpDate
import com.hexagonkt.http.server.Server
import com.hexagonkt.http.server.ServerPort
import com.hexagonkt.http.server.jetty.JettyServletAdapter
import com.hexagonkt.injection.InjectionManager.bindObject

/**
 * Service server. It is created lazily to allow ServerPort injection (set up in main).
 */
val server: Server by lazy {
    Server {
        before {
            response.setHeader("Date", httpDate())
        }

        get("/hello/{name}") { ok("Hello, ${pathParameters["name"]}!", "text/plain") }
    }
}

/**
 * Start the service from the command line.
 */
fun main() {
    bindObject<ServerPort>(JettyServletAdapter()) // Bind Jetty server to HTTP Server Port
    server.start()
}

Features

Hexagon's high-level features.

  • Simple to Use: Hexagon is focused in allowing you to use the features you use the most in your daily coding in the easiest way.

  • Easy to Hack: The library is done to be lean and simple so you can tweak it to suit your needs instead relying on third parties.

  • Pluggable Adapters: Adding an adapter is just implementing the port's interface. You can code your own adapters from scratch or tune the existing ones.

  • Kotlin First: The library is coded in Kotlin for coding with Kotlin. No strings attached to Java (as a Language).

  • Properly Tested: Project's coverage is checked in every Pull Request. It is also stress tested at TechEmpower Frameworks Benchmark.

  • Modular: Each feature is isolated in its own module. Use only the modules you need without unneeded dependencies.

Architecture

How Hexagon fits in your architecture in a picture.

architecture

Ports

Ports with their provided implementations (Adapters).

PORT ADAPTERS
HTTP Server Jetty, Servlet
Templates Pebble
Serialization Formats JSON, YAML
Settings Environment, Files, Resources