Kelp meets Raisin!

Give you Kelp application some Raisin juice (or vice versa)


What is Kelp?

Kelp is a web framework I'm currently maintaining. It is a very good choice for applications that rely heavily on Plack. It also has very similar structure to Mojolicious, which allows for a very easy transition between the two.

What is Raisin?

Raisin is a REST microframework inspired by Kelp. It is a standalone Plack application builder specifically designed for API creation. It has some very good features built in, like Swagger integration. Definetly check it out.

The bridge between the two

Raisin could have already been integrated into Kelp quite easily in the .psgi script:

use Plack::Builder;
use RaisinApp;
use KelpApp;

builder {
    mount '/' => KelpApp->new->run;
    mount '/api/rest' => RaisinApp->new;
};

This however allowed for no integration between the two - they were just two Plack applications running alongside each other within the same routing table. With my new Kelp::Module::Raisin you can integrate them the same way just using Kelp configuration:

modules => [Symbiosis Raisin],
modules_init => {
    Raisin => {
        mount => '/api/rest',
        class => 'RaisinApp'
    }
}

This will have the same effect as the .psgi script above, while it can be reduced to:

use KelpApp;

KelpApp->new->run_all;

This is made possible with the help of Kelp::Module::Symbiosis. It can make multiple Plack applications submit to Kelp's will. But the most interesting thing about this integration is that we can now change Raisin from inside Kelp:

sub build {
    my $self = shift;

    $self->raisin->add_route(
            method => 'GET',
            path => '/raisin-route',
            params => [],
            code => sub {
                "We just accessed Raisin from Kelp"
                . ", here's the proof: " . $self->proof
            },
    );
}

sub proof {
    'I AM THE PROOF!'
}

So now the route /api/rest/raisin-route will be created and available, which opens up new integration possibilities between the applications.


Comments? Suggestions? Send to feedback@brtastic.xyz
Published on 2021-01-16