Link Search Menu Expand Document


You can use redirect to redirect the browser to a relative or absolute path. The defaul redirection is temporary (status code 302) but you can also use a specific HTTP 3xx status code.

import topinambur.http

fun `redirect to relative path`() {
        .any("/foo") { _, res -> res.redirect("/bar", MOVED_PERMANENTLY_301) }
        .any("/bar") { _, res -> res.write("Hello") }
        .start().use {
            assertThat("http://localhost:4545/foo".http.get(followRedirects = true).body).isEqualTo("Hello")

An Open Source Project