Created
August 3, 2016 21:58
-
-
Save jkramer/7a2ca87909e3cd9abd945a043417de41 to your computer and use it in GitHub Desktop.
Blurgh Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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