Skip to content

Instantly share code, notes, and snippets.

@Syuparn
Created January 2, 2022 08:01
Show Gist options
  • Save Syuparn/f28524b7ae62edc92a06bc8ad0a67855 to your computer and use it in GitHub Desktop.
Save Syuparn/f28524b7ae62edc92a06bc8ad0a67855 to your computer and use it in GitHub Desktop.
Cro sample REST API server
unit module MyController;
sub hello($name) is export {
{
name => $name,
};
}
version: '3'
services:
cro:
build: .
tty: true
ports:
- 8080:8080
FROM croservices/cro-http:0.8.5
RUN mkdir /app
COPY . /app
WORKDIR /app
RUN raku -c -Ilib main.p6
CMD raku -Ilib main.p6
use Cro::HTTP::Router;
use Cro::HTTP::Server;
use MyController;
my $application = route {
get -> 'greet', $name {
content 'application/json', MyController::hello($name);
}
}
my Cro::Service $hello = Cro::HTTP::Server.new:
:host<0.0.0.0>, :port<8080>, :$application;
$hello.start;
react whenever signal(SIGINT) { $hello.stop; exit; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment