croservices / cro-http

HTTP (including HTTPS and HTTP/2) support for the Cro library for building distributed systems in Raku.
https://cro.services/
Artistic License 2.0
49 stars 26 forks source link

Support link generation #152

Open Altai-man opened 3 years ago

jnthn commented 2 years ago

Doing some testing. Some findings:

my $application = route {
    get :name<home>, -> {
        content 'text/plain', join "\n",
            # Fine
            abs-link('home'),
            abs-link('lit'),
            abs-link('qs', 'tools', query => 'abc?!'),
            abs-link('qs', 'tools'),
            # Fails to % encode the space
            abs-link('segs', 42, 'foo bar.jpg'),
            # Should not consider `is cookie` and `is header`
            abs-link('noqs'),
            '';
    }

    get :name<lit>, -> 'foo', 'bar' { }

    get :name<segs>, -> 'product', $id, 'docs', $file { }

    get :name<qs>, -> 'search', $category, :$query {}

    get :name<noqs>, -> 'baz', :$foo! is cookie, :$bar! is header {}
}
jnthn commented 2 years ago

If I change the above example to:

route :name<root>, {

Then all of the examples stop working, complaining that they want the qualified name, however qualification should be optional.

jnthn commented 2 years ago

Also expanded with some non-working ones for included routes:

my $application = route {
    get :name<home>, -> {
        content 'text/plain', join "\n",
            # Fine
            abs-link('home'),
            abs-link('lit'),
            abs-link('qs', 'tools', query => 'abc?!'),
            abs-link('qs', 'tools'),
            # Fails to % encode the space
            abs-link('segs', 42, 'foo bar.jpg'),
            # Should not consider `is cookie` and `is header`
#            abs-link('noqs'),
            # These don't work (routes not found)           
            abs-link('blog.home'),
            abs-link('blog.post', 42),
            '';
    }       

    get :name<lit>, -> 'foo', 'bar' { }

    get :name<segs>, -> 'product', $id, 'docs', $file { }

    get :name<qs>, -> 'search', $category, :$query {}

    get :name<noqs>, -> 'baz', :$foo! is cookie, :$bar! is header {}

    include 'blog' => route :name<blog>, {
        get :name<home>, -> {}
        get :name<post>, -> 'post', $id {}
    }
}