Git Product home page Git Product logo

p5-json-rpc-spec's Introduction

Build Status

NAME

JSON::RPC::Spec - Yet another JSON-RPC 2.0 Implementation

SYNOPSIS

use strict;
use JSON::RPC::Spec;

my $rpc = JSON::RPC::Spec->new;

# server
$rpc->register(echo => sub { $_[0] });
print $rpc->parse(
    '{"jsonrpc": "2.0", "method": "echo", "params": "Hello, World!", "id": 1}'
);    # -> {"jsonrpc":"2.0","result":"Hello, World!","id":1}

# client
print $rpc->compose(echo => 'Hello, World!', 1);
  # -> {"jsonrpc":"2.0","method":"echo","params":"Hello, World!","id":1}

DESCRIPTION

JSON::RPC::Spec is Yet another JSON-RPC 2.0 Implementation.

JSON format string execute registered method.

JSON::RPC - PSGI

The tightly also supports BATCH.

As a feature. 1. JSON string to JSON string. 2. Simple register callback.

FUNCTIONS

new

constructor.

options "coder" in JSON::RPC::Spec::Common and "router" are available.

register

# method => code refs
use List::Util qw(max);
$rpc->register(max => sub { max(@{$_[0]}) });

# method matching via Router::Simple
$rpc->register('myapp.{action}' => sub {
    my ($params, $match) = @_;
    my $action = $match->{action};
    return MyApp->new->$action($params);
});

register method.

parse

my $result = $rpc->parse(
    '{"jsonrpc": "2.0", "method": "max", "params": [9,4,11,0], "id": 1}'
);    # returns JSON encoded string -> {"id":1,"result":11,"jsonrpc":"2.0"}

parse JSON and triggered method. returns JSON encoded string.

parse_without_encode

my $result = $rpc->parse_without_encode(
    '{"jsonrpc": "2.0", "method": "max", "params": [9,4,11,0], "id": 1}'
);    # returns hash -> {id => 1, result => 11, jsonrpc => '2.0'}

parse JSON and triggered method. returns HASH.

compose

See "compose" in JSON::RPC::Spec::Client for full documentation.

router

similar Router::Simple.

DEBUGGING

You can set the PERL_JSON_RPC_SPEC_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.

PERL_JSON_RPC_SPEC_DEBUG = 1

SEE ALSO

http://search.cpan.org/dist/JSON-RPC/

http://search.cpan.org/dist/JSON-RPC-Dispatcher/

http://search.cpan.org/dist/JSON-RPC-Common/

LICENSE

Copyright (C) nqounet.

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

AUTHOR

nqounet <[email protected]>

p5-json-rpc-spec's People

Contributors

nqounet avatar

Watchers

Mohammad Sajid Anwar avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.