Link Search Menu Expand Document

Methods

Currently supported methods:

ANY

You can use any if you don’t care about the request method

import topinambur.http

@Test
fun any() {
    HttpServer()
        .any("/foo") { _, res -> res.write("Hello") }
        .start().use {
            assertThat("http://localhost:4545/foo".http.get().body).isEqualTo("Hello")
            assertThat("http://localhost:4545/foo".http.post().body).isEqualTo("Hello")
        }
}

GET

import topinambur.http

@Test
fun get() {
    HttpServer()
        .get("/foo") { _, res -> res.write("Hello") }
        .start().use {
            assertThat("http://localhost:4545/foo".http.get().body).isEqualTo("Hello")
        }
}

POST

import topinambur.http

@Test
fun post() {
    HttpServer()
        .post("/foo") { _, res -> res.write("Hello") }
        .start().use {
            assertThat("http://localhost:4545/foo".http.post().body).isEqualTo("Hello")
        }
}
import topinambur.http

@Test
fun head() {
    HttpServer()
        .head("/foo") { _, res -> res.status(ACCEPTED_202) }
        .start().use {
            assertThat("http://localhost:4545/foo".http.head().statusCode).isEqualTo(ACCEPTED_202)
        }
}

PUT

import topinambur.http

@Test
fun put() {
    HttpServer()
        .put("/") { _, res -> res.status(NO_CONTENT_204) }
        .start().use {
            assertThat("http://localhost:4545/".http.put().statusCode).isEqualTo(NO_CONTENT_204)
        }
}

DELETE

import topinambur.http

@Test
fun delete() {
    HttpServer()
        .delete("/") { _, res -> res.status(NO_CONTENT_204) }
        .start().use {
            assertThat("http://localhost:4545/".http.delete().statusCode).isEqualTo(NO_CONTENT_204)
        }
}

OPTIONS

import topinambur.http

@Test
fun options() {
    HttpServer()
        .options("/") { _, res -> res.status(OK_200) }
        .start().use {
            assertThat("http://localhost:4545/".http.options().statusCode).isEqualTo(OK_200)
        }
}

An Open Source Project