Skip to content

Quick Start

In this guide, we are going to create a sample HTTP service. You can read the Core or HTTP Server modules documentation for more information. You can use both Gradle and Maven to build your application.

You can start by cloning a starter project (Gradle Starter or Maven Starter). Or you can create a project from scratch following these steps:

  1. Configure Kotlin in Gradle or Maven.
  2. Add the dependency in Gradle or Maven:
1
2
3
4
5
repositories {
    mavenCentral()
}

implementation("com.hexagonkt:http_server_jetty:$hexagonVersion")
1
2
3
4
5
<dependency>
  <groupId>com.hexagonkt</groupId>
  <artifactId>http_server_jetty</artifactId>
  <version>$hexagonVersion</version>
</dependency>
  1. Write the code in the src/main/kotlin/Hello.kt file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import com.hexagonkt.core.media.TEXT_PLAIN
import com.hexagonkt.http.model.ContentType
import com.hexagonkt.http.server.HttpServer
import com.hexagonkt.http.server.jetty.serve

lateinit var server: HttpServer

/**
 * Start a Hello World server, serving at path "/hello".
 */
fun main() {
    server = serve {
        get("/hello/{name}") {
            val name = pathParameters["name"]
            ok("Hello $name!", contentType = ContentType(TEXT_PLAIN))
        }
    }
}
  1. Run the service and view the results at: http://localhost:2010/hello/hex

Dependencies Verification

Hexagon's dependencies are signed, you can get the public key at the OpenPGP Public Key Server or here.

These are the details of the public key:

1
2
pub  4096R/2AEE3721 2020-05-30 Hexagon Toolkit (Key used to sign published binaries) <project@hexagonkt.com>
     Fingerprint=792B D37F F598 91C4 AC6F  8D92 3B26 711D 2AEE 3721

Next Steps

To continue learning about this toolkit, you can:

  • Read the Core or HTTP Server modules documentation for details on specific modules.
  • Clone the Gradle Starter or Maven Starter repository for a minimal fully working example (including tests).
  • Proceed to the Examples section to check code snippets or full example projects.