Cro – elegant reactive services in Raku

giancarlostoro1 pts0 comments

Cro - elegant reactive services in Raku

Welcome to Cro

Cro is a set of libraries for building reactive distributed systems,<br>lovingly crafted to take advantage of all Raku has to offer. The high<br>level APIs make the easy things easy, and the asynchronous pipeline<br>concept at Cro's heart makes the hard things possible.

Ready to get started? Just zef install --/test cro<br>and check out the documentation.

HTTP

Web Sockets

Tooling

Set up your routes, and serve them

use Cro::HTTP::Router;<br>use Cro::HTTP::Server;<br>my $application = route {<br>get -> 'greet', $name {<br>content 'text/plain', "Hello, $name!";<br>my Cro::Service $hello = Cro::HTTP::Server.new:<br>:host, :port, :$application;<br>$hello.start;<br>react whenever signal(SIGINT) { $hello.stop; exit; }

Built-in HTTP server

HTTP/1.1 persistent connections

HTTP/2.0 (use negotiated with ALPN)

HTTPS support

Add middleware at the server level

Configure body parsers and serializers

Requests dispatched to the thread pool, to make use<br>of multi-core CPUs

Flexible request router

# Capture/constrain root segments with a signature.<br>get -> 'product', UUIDv4 $id {<br>content 'application/json', get-product($id);<br># Slurp root segments and serve static content<br>get -> 'css', *@path {<br>static 'assets/css', @path;<br># Get stuff from the query string<br>get -> 'search', :$term! {<br>content 'application/json', do-search($term);

Pluggable body parsing and serialization

Enjoy built-in support for www-form-urlencoded, multi-part,<br>and JSON bodies - or plug in your own body parsers and<br>serializers.

put -> 'order', UUIDv4 $id {<br>request-body -> %json-object {<br># Save it, and then...<br>content 'application/json', %json-object;

HTTP client included

Asynchronous API for getting the response and the<br>body (body delivered all at once or streaming)

Supports HTTP/1.1 persistent connections

HTTPS, with optional custom certificate authority

HTTP/2.0 support, with request multiplexing

Pluggable body parsers/serializers - the same used by<br>the server - and middleware support

Previous

Next

Neatly integrated with the HTTP router

my $chat = Supplier.new;<br>get -> 'chat' {<br>web-socket -> $incoming {<br>supply {<br>whenever $incoming -> $message {<br>$chat.emit(await $message.body-text);<br>whenever $chat -> $text {<br>emit $text;

Web socket client

A Supply-based web services client is included<br>in Cro.

It's just what you need for using web sockets between services,<br>writing web socket clients, or writing integration tests for<br>services exposed by a web socket.

Previous

Next

Get started with good defaults

The cro stub ... command stubs new HTTP and<br>ZeroMQ services.

As well as helping you get started faster, it also helps<br>you to set off in a good direction. For example, it<br>accepts host and port from the environment (great for<br>container deployment), and generates a META6.json<br>for declaring the service dependencies.

cro run

A lightweight development service runner.

Starts services, automatically assigning them free ports

Automatically restarts services when their code changes

Collects and displays service output - telling you which<br>output came from which service

cro trace

Runs one or more services with tracing enabled.

Tracing enables you to see how requests progress through<br>the asynchronous pipeline, helping you to more rapidly<br>understand where a problem occurs.

Previous

Next

So you know: Cro is currently in BETA. We're overall<br>quite satisfied with most of the APIs, and don't plan major changes in<br>this regard. Expect some bumps on the road - and if you run into any of<br>them, please consider<br>filing a bug report so we can make things better.

http services body json server application

Related Articles