-
-
Save tomatophobia/260ae0738266b12c2497ff4eb47935e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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