Home

The Hexagon Toolkit provides several libraries to build server applications. These libraries provide single standalone features1 and are referred to as "Ports".

The main ports are:

  • The HTTP server: supports HTTPS, HTTP/2, mutual TLS, static files (serve and upload), forms processing, cookies, sessions, CORS and more.
  • The HTTP client: which supports mutual TLS, HTTP/2 and cookies among other features.

Each of these features or ports may have different implementations called "Adapters".

Hexagon is designed to fit in applications that conform to the Hexagonal Architecture (also called Clean Architecture or Ports and Adapters Architecture). Also, its design principles also fits in this architecture.

Hello World

Simple Hello World HTTP example.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package com.hexagonkt.http.server.jetty

import com.hexagonkt.http.server.Server

lateinit var server: Server

fun main() {
    server = Server(JettyServletAdapter()) {
        get("/hello") {
            ok("Hello World!")
        }
    }

    server.start()
}

You can check the code examples and demo projects for more complex use cases.

Features

Hexagon's goals and design principles:

  • Put you in Charge: There is no code generation, no runtime annotation processing and no logic based on your classpath. You control your tools, not the other way around.

  • Modular: Each feature (Port) or adapter is isolated in its own module. Use only the modules you need without carrying unneeded dependencies.

  • Pluggable Adapters: Every Port may have many implementations (Adapters) using different technologies. You can swap adapters without changing application code.

  • Batteries Included: It contains all required pieces to make production grade applications: settings management, serialization and dependency injection2.

  • Kotlin First: Take full advantage of Kotlin instead just calling Java code from Kotlin. 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.

Architecture

How Hexagon fits in your architecture in a picture.

Note

Using this toolkit won't make your application compliant with Hexagonal Architecture (by its nature, no tool can do that), you have to provide a layer of abstraction by yourself.

architecture

Ports

Ports with their provided implementations (Adapters).

PORT ADAPTERS
HTTP Server Jetty, Servlet
HTTP Client AHC
Messaging RabbitMQ
Store MongoDB
Templates Pebble, FreeMarker
Serialization Formats JSON, YAML
Settings Environment, Files, Resources

  1. Except the Core module that contains a set of utilities like serialization and dependency injection. However, some of these capacities can be replaced by other third party libraries. 

  2. However, you can replace the core DI implementation with any other library. 

Comments