reference: Cro - Getting started with Cro
Created
January 2, 2022 08:01
-
-
Save Syuparn/f28524b7ae62edc92a06bc8ad0a67855 to your computer and use it in GitHub Desktop.
Cro sample REST API server
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
unit module MyController; | |
sub hello($name) is export { | |
{ | |
name => $name, | |
}; | |
} |
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
version: '3' | |
services: | |
cro: | |
build: . | |
tty: true | |
ports: | |
- 8080:8080 |
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
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 |
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 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