NAME

Async::Microservice - Async HTTP Microservice Moose Role

SYNOPSYS

# 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!

DESCRIPTION

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.

To bootstrap new async service

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.

Copy one of the bin/*.psgi update it with your new package name.

Copy one of the root/static/*.yaml to have the same name as service_name.

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

SEE ALSO

OpenAPI Specification: https://github.com/OAI/OpenAPI-Specification/tree/master/versions or https://swagger.io/docs/specification/about/

Async::MicroserviceReq Twiggy

TODO

- 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

CONTRIBUTORS & CREDITS

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/.

BUGS

Please report any bugs or feature requests via https://github.com/jozef/Async-Microservice/issues.

AUTHOR

Jozef Kutej

COPYRIGHT & LICENSE

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.