Cro – elegant reactive services in Raku

Hacker News Top Tools

Summary

Cro is a set of Raku libraries for building reactive distributed systems, featuring an HTTP server with router, WebSocket support, and asynchronous pipelines.

No content available
Original Article
View Cached Full Text

Cached at: 08/03/26, 07:37 AM

# elegant reactive services in Raku Source: [https://cro.raku.org/](https://cro.raku.org/) ## Welcome to Cro Cro is a set of libraries for building reactive distributed systems, lovingly crafted to take advantage of all Raku has to offer\. The high level APIs make the easy things easy, and the asynchronous pipeline concept at Cro's heart makes the hard things possible\. Ready to get started? Just`zef install \-\-/test cro`and check out the[documentation](https://cro.raku.org/docs)\. - [HTTP](https://cro.raku.org/#http) - [Web Sockets](https://cro.raku.org/#ws) - [Tooling](https://cro.raku.org/#tooling) ## Set up your routes, and serve them ``` use Cro::HTTP::Router; use Cro::HTTP::Server; my $application = route { get -> 'greet', $name { content 'text/plain', "Hello, $name!"; } } my Cro::Service $hello = Cro::HTTP::Server.new: :host<localhost>, :port<10000>, :$application; $hello.start; react whenever signal(SIGINT) { $hello.stop; exit; } ``` ## Built\-in HTTP server ![](https://cro.raku.org/images/glyphicon-ok.png) HTTP/1\.1 persistent connections ![](https://cro.raku.org/images/glyphicon-ok.png) HTTP/2\.0 \(use negotiated with ALPN\) ![](https://cro.raku.org/images/glyphicon-ok.png) HTTPS support ![](https://cro.raku.org/images/glyphicon-ok.png) Add middleware at the server level ![](https://cro.raku.org/images/glyphicon-ok.png) Configure body parsers and serializers ![](https://cro.raku.org/images/glyphicon-ok.png) Requests dispatched to the thread pool, to make use of multi\-core CPUs ## Flexible request router ``` # Capture/constrain root segments with a signature. get -> 'product', UUIDv4 $id { content 'application/json', get-product($id); } # Slurp root segments and serve static content get -> 'css', *@path { static 'assets/css', @path; } # Get stuff from the query string get -> 'search', :$term! { content 'application/json', do-search($term); } ``` ## Pluggable body parsing and serialization Enjoy built\-in support for www\-form\-urlencoded, multi\-part, and JSON bodies \- or plug in your own body parsers and serializers\. ``` put -> 'order', UUIDv4 $id { request-body -> %json-object { # Save it, and then... content 'application/json', %json-object; } } ``` ## HTTP client included ![](https://cro.raku.org/images/glyphicon-ok.png) Asynchronous API for getting the response and the body \(body delivered all at once or streaming\) ![](https://cro.raku.org/images/glyphicon-ok.png) Supports HTTP/1\.1 persistent connections ![](https://cro.raku.org/images/glyphicon-ok.png) HTTPS, with optional custom certificate authority ![](https://cro.raku.org/images/glyphicon-ok.png) HTTP/2\.0 support, with request multiplexing ![](https://cro.raku.org/images/glyphicon-ok.png) Pluggable body parsers/serializers \- the same used by the server \- and middleware support [![](https://cro.raku.org/images/glyphicon-left.png)Previous](https://cro.raku.org/#carousel-http)[![](https://cro.raku.org/images/glyphicon-right.png)Next](https://cro.raku.org/#carousel-http) ## Neatly integrated with the HTTP router ``` my $chat = Supplier.new; get -> 'chat' { web-socket -> $incoming { supply { whenever $incoming -> $message { $chat.emit(await $message.body-text); } whenever $chat -> $text { emit $text; } } } } ``` ## Web socket client A`Supply`\-based web services client is included in Cro\. It's just what you need for using web sockets between services, writing web socket clients, or writing integration tests for services exposed by a web socket\. [![](https://cro.raku.org/images/glyphicon-left.png)Previous](https://cro.raku.org/#carousel-websockets)[![](https://cro.raku.org/images/glyphicon-right.png)Next](https://cro.raku.org/#carousel-websockets)

Similar Articles

tokio-rs/topcoat

GitHub Trending (daily)

Topcoat is a modular, batteries-included Rust framework for building fullstack apps with server-side rendering and client reactivity without a separate API layer.