The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Beekeeper::JSONRPC::Request - Representation of a JSON-RPC request

VERSION

Version 0.09

SYNOPSIS

  my $client = Beekeeper::Client->instance;
  
  my $req = $client->call_remote_async(
      method => 'myapp.svc.foo',
      params => { foo => 'bar' },
  );
  
  $client->wait_async_calls;
  
  die unless ($req->success);
  
  print $req->result;

DESCRIPTION

Objects of this class represent a JSON-RPC request (see http://www.jsonrpc.org/specification).

The method Beekeeper::Client::call_remote_async returns objects of this class.

On worker classes the method handlers setted by Beekeeper::Worker::accept_remote_calls will receive these objects as parameters.

ACCESSORS

method

Returns a string with the name of the method invoked.

params

Returns the arbitrary data structure passed as parameters.

id

A value of any type, which is used to match responses with requests.

response

Once the request is complete, it returns the corresponding Beekeeper::JSONRPC::Response or Beekeeper::JSONRPC::Error object.

result

Once the request is complete, it returns the result encapsulated in the response.

It is just a shortcut for $req->response->result.

success

Once the request is complete, it returns true unless the response is an error. It is used to determine if a method was executed successfully or not ($response->result cannot be trusted as it may be undefined on success).

Returns undef if the request is in still progress.

It is just a shortcut for $req->response->success.

mqtt_properties

Returns a hashref containing the MQTT properties of the request.

METHODS

async_response

On worker classes remote calls can be processed concurrently by means of calling $req->async_response to tell Beekeeper that the response for the request will be deferred until it is available, freeing the worker to accept more requests.

Once the response is ready, it must be sent back to the caller with $req->send_response.

send_response ( $val )

Send back to the caller the provided value or data structure as response.

Error responses can be returned sending Beekeeper::JSONRPC::Error objects.

SEE ALSO

Beekeeper::Client, Beekeeper::Worker.

AUTHOR

José Micó, jose.mico@gmail.com

COPYRIGHT AND LICENSE

Copyright 2015-2021 José Micó.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language itself.

This software is distributed in the hope that it will be useful, but it is provided “as is” and without any express or implied warranties. For details, see the full text of the license in the file LICENSE.