Skip to content

Instantly share code, notes, and snippets.

@jkramer
Created August 3, 2016 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkramer/7a2ca87909e3cd9abd945a043417de41 to your computer and use it in GitHub Desktop.
Save jkramer/7a2ca87909e3cd9abd945a043417de41 to your computer and use it in GitHub Desktop.
Blurgh Example
use Blurgh;
class Blog::Post does Blurgh::Route[:('post')] {
state %posts;
state $next-post-id = 1;
# Matches "GET /post/123" (only if integer exists in %posts)
multi method get(Int:D $id where { %posts{$_}:exists }) {
$.render(:text(%posts{$id}));
}
# Matches POST /post/new
multi method post('new') {
my $id = $next-post-id++;
%posts{$id} = $.request.data.decode;
$.render(:text("post $id created"));
}
}
run(Blog::Post);
---
# curl -d 'Lustiger Post.' localhost:8118/post/new
post 1 created
# curl localhost:8118/post/1
Lustiger Post
# curl localhost:8118/post/2
Not Found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment