Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Last active August 21, 2021 18:02
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 jonathanstowe/f9d342d11e5b88aca2dd614a1eacc090 to your computer and use it in GitHub Desktop.
Save jonathanstowe/f9d342d11e5b88aca2dd614a1eacc090 to your computer and use it in GitHub Desktop.
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