Skip to content

Instantly share code, notes, and snippets.

@daviddenton
Created October 16, 2020 17:09
Show Gist options
  • Save daviddenton/96004fd0961e85ae4a66c53464733a11 to your computer and use it in GitHub Desktop.
Save daviddenton/96004fd0961e85ae4a66c53464733a11 to your computer and use it in GitHub Desktop.
Composing multiple http4k apps
val app1 = routes(
"/bob" bind GET to { Response(OK).body("you GET bob") },
"/rita" bind POST to { Response(CREATED).body("you POST rita") }
)
val app2 = routes(
"/sue" bind DELETE to { Response(ACCEPTED).body("you DELETE sue") }
)
// we can compose the apps together into one large app here at the root,
// prefix them with other paths, or filter on headers etc..
val bigApp: HttpHandler = routes(app1, app2)
bigApp(Request(GET, "/bob").status // OK
bigApp(Request(DELETE, "/sue").status // ACCEPTED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment