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
After the literal
'hello', the$namein the signature captures the next URL segment — so/hello/Annabinds$nametoAnna.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
$applicationto aCro::HTTP::Serverand starting it would make the route reachable.