khrt / Raisin

Raisin - a REST API micro framework for Perl 🐫 🐪
61 stars 29 forks source link

multiple route_param example #81

Closed lmasarati closed 4 years ago

lmasarati commented 4 years ago

Hello, I'm wondering if an API call like this could be done and how... GET http://example/api/:id1/:id2/:id3

The goal is to receive the three route_param id1, id2 and id3 in the get sub {} and then process them as needed... Thanks.

khrt commented 4 years ago

I think it's related to #77

lmasarati commented 4 years ago

yes, I suspected... So the sample code could be something like this?

desc "multiple route_param";
resource "api" => sub {
    params(
        requires('id1', type => Str, desc => "ID1")
        requires('id2', type => Str, desc => "ID2"),
        requires('id3', type => Str, desc => "ID3")
    );
    route_param 'id1' => sub {
        route_param 'id2' => sub {
            route_param 'id3' => sub {
                get sub {
                    my $params = shift;
                    return $params;
                };
            };
        };
    };
};
khrt commented 4 years ago

Yes, exactly. Once I fix it. Unfortunately I had no time yet to work on it, but it's my priority to fix.

khrt commented 4 years ago

Here is a better example:

    params requires => { name => 'id', type => Int };
    route_param id => sub {
        get sub { ... };

        params requires => { name => 'sub_id', type => Int };
        route_param sub_id => sub {
            ...
        };
    };

Also extended documentation: https://github.com/khrt/Raisin/blob/93e806c/lib/Raisin.pm#L458

khrt commented 4 years ago

Fix for #77 was merged and realised to CPAN, see Raisin 0.87