Core

Humming-Bird::Core

A simple imperative web framework. Similar to Opium (OCaml) and Express (JavaScript). Humming-Bird aims to provide a simple, straight-forward HTTP Application server. Humming-Bird is not designed to be exposed to the world-wide web without a reverse proxy, I recommend NGiNX. This is why TLS is not implemented.

Exported subroutines

get, post, put, patch, delete

    get('/home', -> $request, $response {
      $response.html('<h1>Hello World</h1>');
    });
post('/users', -> $request, $response {
      my $text = sprintf("Hello: %s", $request.body);
      $response.write($text); # Content type defaults to text/plain
    });
delete ...
    put ...
    patch ...
    head ...

Register an HTTP route, and a Block that takes a Request and a Response. It is expected that the route handler returns a valid Response, in this case .html returns the response object for easy chaining. There is no built in body parsers, so you'll have to convert bodies with another library, JSON::Fast is a good option for JSON!

group

    # Add middleware to a few routes
    group([
        &get.assuming('/', -> $request, $response {
            $response.html('Index');
        }),
&get.assuming('/other', -> $request, $response {
            $response.html('Other');
        })
    ], [ &m_logger, &my_middleware ]);

Group registers multiple routes functionally via partial application. This allows you to group as many different routes together and feed them a List of middleware in the last parameter. Group takes a List of route functions partially applied to their route and callback, then a List of middleware to apply to the routes.

listen

    listen(8080);

Start the server, after you've declared your routes. It will listen in a given port.

routes

    routes();

Returns a read-only version of the currently stored routes.

HTTPMethod

Simply an ENUM that contains the major HTTP methods allowed by Humming-Bird.

Humming-Bird::Core v2.0.0

A simple, composable Web Framework.

Authors

  • Rawley Fowler

License

MIT

Dependencies

HTTP::StatusDateTime::Format

Provides

  • Humming-Bird::Advice
  • Humming-Bird::Core
  • Humming-Bird::HTTPServer
  • Humming-Bird::Middleware

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.