Last active
August 21, 2021 18:02
-
-
Save jonathanstowe/f9d342d11e5b88aca2dd614a1eacc090 to your computer and use it in GitHub Desktop.
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 Cro::HTTP::Router; | |
use Cro::HTTP::Server; | |
use JSON::Class; | |
use Cro::HTTP::BodySerializerJSONClass; | |
class Foo does JSON::Class { | |
has DateTime $.date is marshalled-by('Str') = DateTime.now; | |
} | |
my $app = route { | |
get -> { | |
content 'application/json', Foo.new; | |
} | |
}; | |
my Cro::Service $service = Cro::HTTP::Server.new( | |
host => 'localhost', | |
port => 7798, | |
application => $app, | |
add-body-serializers => [ Cro::HTTP::BodySerializerJSONClass] | |
); | |
$service.start; | |
react whenever signal(SIGINT) { $service.stop; exit; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment