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