Skip to content

Instantly share code, notes, and snippets.

@FCO
Created February 22, 2024 22:01
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 FCO/e08b717af876276602428f8147c08b7e to your computer and use it in GitHub Desktop.
Save FCO/e08b717af876276602428f8147c08b7e to your computer and use it in GitHub Desktop.
$ raku -MCro::HTTP::Server -MCro::HTTP::Router -e '
Cro::HTTP::Server.new(
host => "127.0.0.1",
port => 10001,
application => route {my $CRO-ROUTER-RESPONSE = $*CRO-ROUTER-RESPONSE;
get -> {content "test/plain", "ok!"}
^3 .map: -> $i {
post -> Int $a where { say "$_ == $i -> { $_ == $i }"; $_ == $i } {
CATCH { default { say "ERROR: $_" } }
request-body -> %data {
dd %data;
say "running $a == $i";
content "test/plain", "ok"
}
}
}
}
).start;
react whenever signal(SIGINT) {exit}
'
$ curl -v 127.0.0.1:10001/2 -d a=b
* Trying 127.0.0.1:10001...
* Connected to 127.0.0.1 (127.0.0.1) port 10001 (#0)
> POST /2 HTTP/1.1
> Host: 127.0.0.1:10001
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 3
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Transfer-encoding: chunked
<
* Connection #0 to host 127.0.0.1 left intact
2 == 2 -> True
2 == 0 -> False
2 == 0 -> False
Constraint type check failed in binding to parameter '$a'; expected anonymous constraint to be met but got Int (2)
in block at -e line 9
in block at /Users/fernandooliveira/.rakubrew/versions/moar-main/install/share/perl6/site/sources/0A956E7216D9483D5E509D21341F86CD95BF92D0 (Cro::HTTP::Router) line 201
in block at /Users/fernandooliveira/.rakubrew/versions/moar-main/install/share/perl6/site/sources/0A956E7216D9483D5E509D21341F86CD95BF92D0 (Cro::HTTP::Router) line 197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment