Welcome to Cro

cro.raku.org · 2026-08-03 · by Long Nguyen ·generic
Cro - elegant reactive services in Raku

Welcome to Cro

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.

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

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 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

Asynchronous API for getting the response and the 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 the server - and middleware support

Previous Next

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.

Previous Next

Get started with good defaults

The `cro stub ...` command stubs new HTTP and ZeroMQ services.

As well as helping you get started faster, it also helps you to set off in a good direction. For example, it accepts host and port from the environment (great for container deployment), and generates a `META6.json`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 output came from which service

cro trace

Runs one or more services with tracing enabled.

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

Previous Next

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

cro.raku.org · 5 images · 5 links

Comments (0)

No comments yet