Async::Microservice - Async HTTP Microservice Moose Role
# lib/Async/Microservice/HelloWorld.pm package Async::Microservice::HelloWorld; use Moose; with qw(Async::Microservice); sub service_name {return 'asmi-helloworld';} sub get_routes {return ('hello' => {defaults => {GET => 'GET_hello'}});} sub GET_hello { my ( $self, $this_req ) = @_; return [ 200, [], 'Hello world!' ]; } 1; # bin/async-microservice-helloworld.psgi use Async::Microservice::HelloWorld; my $mise = Async::Microservice::HelloWorld->new(); return sub { $mise->plack_handler(@_) }; $ plackup -Ilib --port 8089 --server Twiggy bin/async-microservice-helloworld.psgi $ curl http://localhost:8089/v1/hello Hello world!
This Moose::Role helps to quicly bootstrap async http service that is including OpenAPI documentation.
See https://time.meon.eu/ and Async::Microservice::Time code.
Create new package for your APIs from current examples lib/Async/Microservice/*. Inside set return value of service_name. This string will be used to set process name and to read/locate OpenAPI yaml definition for the documentation. Any GET/POST processing funtions must be defined in get_routes funtion.
lib/Async/Microservice/*
service_name
get_routes
Copy one of the bin/*.psgi update it with your new package name.
bin/*.psgi
Copy one of the root/static/*.yaml to have the same name as service_name.
root/static/*.yaml
Now you are able to lauch the http service with:
plackup -Ilib --port 8089 --server Twiggy bin/async-microservice-YOUNAME.psgi
In your broser you can read the OpenAPI documentation: http://0.0.0.0:8089/v1/ and also use editor to extend it: http://0.0.0.0:8089/v1/edit
OpenAPI Specification: https://github.com/OAI/OpenAPI-Specification/tree/master/versions or https://swagger.io/docs/specification/about/
Async::MicroserviceReq Twiggy
- graceful termination (finish all requests before terminating on sigterm/hup) - systemd service file examples - static/index.html and static/edit.html are not really static, should be moved
The following people have contributed to this distribution by committing their code, sending patches, reporting bugs, asking questions, suggesting useful advice, nitpicking, chatting on IRC or commenting on my blog (in no particular order):
you?
Also thanks to my current day-job-employer https://www.apa-it.at/.
Please report any bugs or feature requests via https://github.com/jozef/Async-Microservice/issues.
Jozef Kutej
Copyright 2020 Jozef Kutej, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Async::Microservice, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Async::Microservice
CPAN shell
perl -MCPAN -e shell install Async::Microservice
For more information on module installation, please visit the detailed CPAN module installation guide.