Course of Raku / Functional, concurrent, reactive, and web programming / Web programming / Cro 101 / Exercises / A route with a parameter

Solution: A route with a parameter

Here is a possible solution to the task.

Code

use Cro::HTTP::Router;

my $application = route {
    get -> 'hello', $name {
        content 'text/plain', "Hello, $name!";
    }
}

🦋 You can find the source code in the file greeting-route.raku.

Output

Hello, Anna!

Comments

  1. After the literal 'hello', the $name in the signature captures the next URL segment — so /hello/Anna binds $name to Anna.

  2. The captured value is then interpolated into the response. This is how Cro reads data straight out of the URL, without any manual parsing — handing $application to a Cro::HTTP::Server and starting it would make the route reachable.

Course navigation

A route with a parameter   |   A second route