Skip to content

Instantly share code, notes, and snippets.

@tomatophobia
Last active May 28, 2021 12:58
Show Gist options
  • Select an option

  • Save tomatophobia/260ae0738266b12c2497ff4eb47935e4 to your computer and use it in GitHub Desktop.

Select an option

Save tomatophobia/260ae0738266b12c2497ff4eb47935e4 to your computer and use it in GitHub Desktop.
def translate(app: HttpApp): HttpApp = {
app.andThen(future => for {
resp <- future
tx <- Translator.future(resp.body)
} yield resp.copy(body = tx))}
def hello(theUri: Uri): HttpRoutes = HttpRoutes.of {
case Request(POST, uri, name) if uri == theUri =>
Future.successful(Response(OK, s"Hello, $name!"))
}
val app: HttpApp = translate(seal(hello(Uri("/hola"))))
// Unit test
val req = Request(POST, Uri("/hola"), "Boston")
// req: Request = Request(POST,Uri(/hola),Boston)
asyncAssert("¡Hola, Boston!", app(req).map(_.body))
// ✔ ¡Hola, Boston!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment