DEV Community

Cover image for Introducing Humming-Bird v3
Rawley Fowler
Rawley Fowler

Posted on

4 1 1 1 1

Introducing Humming-Bird v3

Hey folks! It's been a while!

I've been busy, but I haven't forgotten about Humming-Bird. Actually I've been quite busy trying to figure out Web-Sockets, and swappable back-ends for Humming-Bird, features requested by many!

Web-Sockets have been put on the back-burner for a bit, but swappable back-ends, and many bug-fixes have been completed leading to a new version bump.

A lot has changed, and I'm excited to see what sort of back-ends the community may come up with.

To implement a Humming-Bird back-end, simply write a class that does Humming-Bird::Backend;, and implement the listen routine, with a single argument of a function that takes a Humming-Bird::Glue::Request and returns a Humming-Bird::Glue::Response:

use Humming-Bird::Glue;

unit role Humming-Bird::Backend::MyBackend;

method listen(&handler) {
    my $request  = Humming-Bird::Glue::Request.decode(somehow-get-http-request());
    my $response = &handler($request);
    somehow-send-http-response($response.encode);
}
Enter fullscreen mode Exit fullscreen mode

Now in your Humming-Bird app add the following to the listen clause:

use Humming-Bird::Core;

get('/', -> $request, $response {
    $response.html("Hello World!");
});

listen(:backend(Humming-Bird::Backend::MyBackend));
Enter fullscreen mode Exit fullscreen mode

Thanks for reading, Raku rocks!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
raiph profile image
raiph

To implement a Humming-Bird back-end, simply write a class that does Humming-Bird::Backend ...:

While I know Raku so can guess what you mean, your example doesn't show any class that does anything, which might confuse newbie Rakoons.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more