Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add routers #38

Merged
merged 6 commits into from Feb 26, 2023
Merged

Add routers #38

merged 6 commits into from Feb 26, 2023

Conversation

rawleyfowler
Copy link
Owner

@rawleyfowler rawleyfowler commented Feb 26, 2023

Fixes #37

This PR implements the Router class, that can be used for implementing complex routing schemes.

For example:

use Humming-Bird::Core;

my $router = Router.new(root => '/foo/bar');

# Advice and middleware added will be appended to the routes as they are added.
$router.middleware(-> $request, $response, &next { $response.header('X-MyHeader', 'True') });
$router.advice(-> $response { say $response; $response }); 

$router.get(-> $request, $response { $response.write('abc') }); # Registers a get route on /foo/bar

$route.get('/abc', -> $request, $response { $response.write('abc') }); # Registers a get route on /foo/bar/abc

listen(8080); # No need to register or anything. The router is already registered upon creation.

@rawleyfowler rawleyfowler merged commit cd4b622 into main Feb 26, 2023
@rawleyfowler rawleyfowler deleted the routers branch February 26, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add express style routers
1 participant