Async-Microservice

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        ...
    
        my $plack_handler_sub = sub {
            my ($plack_respond) = @_;
            $this_req->plack_respond($plack_respond);
        ...

DESCRIPTION

    This is an object created for each request handled by
    Async::Microservice. It is passed to all request handling functions as
    the first argument and it provides request information and response
    helper methods.

ATTRIBUTES

        method
        headers
        path
        params
        plack_respond
        static_dir
        base_url
        want_json
        content
        json_content

METHODS

 text_plain(@text_lines)

    Send text plain response.

 respond($status, $headers, $payload)

    Send a PSGI/Plack response.

    $headers must be an array reference of header key/value pairs.

    If $payload is not a reference, it is sent as plain text by default.
    When the request Accept header allows JSON and no explicit Content-Type
    header is already present, plain scalar payloads are wrapped
    automatically as JSON:

        { "data": "..." }

    For error statuses ($status >= 400), scalar payloads are wrapped as:

        { "error": { err_status => ..., err_msg => ... } }

    If $payload is a reference, it is serialized as JSON. When JSONP is
    enabled and a valid callback parameter is present, the response is
    emitted as application/javascript instead of application/json.

 redirect($location_path)

    Send redirect.

 static_ft($file_name, $content_cb)

    Send static file, can be updated/modified using optional callback.

 get_pending_req

    Returns number of currently pending async requests.


----------------------------------------------------------------------------
NAME

    Async::Microservice::Time - example time async microservice

SYNOPSIS

        # can be started using:
        plackup --port 8085 -Ilib --access-log /dev/null --server Twiggy bin/async-microservice-time.psgi
    
        curl "http://localhost:8085/v1/hcheck" -H "accept: application/json"
        curl "http://localhost:8085/v1/epoch"  -H "accept: application/json"
        curl "http://localhost:8085/v1/datetime?time_zone=local" -H "accept: application/json"

DESCRIPTION

    This is an example asynchronous HTTP microservice using
    Async::Microservice. View the source code; it's minimal.

METHODS

 service_name

    Just a name, used to identify process and look for OpenAPI
    documentation.

 get_routes

    Path::Router configuration for dispatching

 http response methods

  GET_datetime

    https://time.meon.eu/v1/datetime

  POST_datetime

        $ curl -X POST "https://time.meon.eu/v1/datetime" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"epoch\":-42}"
        {
           "date" : "1969-12-31",
           "datetime" : "1969-12-31 23:59:18 +0000",
           "day" : "31",
           "epoch" : -42,
           "hour" : "23",
           "minute" : "59",
           "month" : "12",
           "second" : "18",
           "time" : "23:59:18",
           "time_zone" : "+0000",
           "time_zone_name" : "UTC",
           "year" : "1969"
        }



( run in 1.616 second using v1.01-cache-2.11-cpan-39bf76dae61 )