Integrations and Ecosystems
Now, we finally have all the pieces of the puzzle. Over the last several chapters, we’ve accumulated a wide range of capabilities based around libuv’s event loop for a full asynchronous programming environment.
curl
Since our curl client provides results as a Future[HttpResponse], it’s straightforward to plug in to our async request handler pattern:
| def main(args:Array[String]):Unit = { |
| Service() |
| .getAsync("/fetch/example") { r => |
| Curl.get(c"https://www.example.com").map { response => |
| Response(200,"OK",Map(),response.body) |
| } |
| } |
| uv_run(EventLoop.loop, UV_RUN_DEFAULT) |
| } |
This makes writing a straightforward proxy server trivial. But we can make it even cleaner if we write some boilerplate to convert the ...
Get Modern Systems Programming with Scala Native now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.