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

Solution: A second route

Here is a possible solution to the task.

Code

use Cro::HTTP::Router;

my $application = route {
    get -> 'hello' {
        content 'text/plain', 'Hello from Cro!';
    }
    get -> 'bye' {
        content 'text/plain', 'Goodbye!';
    }
}

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

Output

Goodbye!

Comments

  1. A route block can hold as many routes as you like; each get handles one path.

  2. Cro matches the request path to the right route, so /hello and /bye return their own responses.

Course navigation

A second route   |   Addendum 🆕