Created
October 16, 2020 17:09
-
-
Save daviddenton/96004fd0961e85ae4a66c53464733a11 to your computer and use it in GitHub Desktop.
Composing multiple http4k apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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