solution/json-rpc-bundle

Wrapper for Zend2 Json Rpc Server

dev-master 2015-06-02 10:35 UTC

This package is not auto-updated.

Last update: 2022-01-17 13:39:42 UTC


README

Symfony2 Bundle wrapper to Zend JsonRpc Server

Installation

Add solution/json-rpc-bundle to composer.json:

{
   "require": {
        "solution/json-rpc-bundle": "dev-master"
    }
}

Add SolutionJsonRpcBundle to your AppKernel.php:

    $bundles = array(
        ...
        new Solution\JsonRpcBundle\SolutionJsonRpcBundle($this),
    );
}

Configuration

Select bundles you want use json-rpc via annotations so that the bundle will pick them up, and add them to your dependency injection container:

#app/config/config.yml
solution_json_rpc:
    bundles: [ Bundle1, Bundle2 ]

Add route to your routing.yml:

mailer_api:
    resource: @SolutionJsonRpcBundle/Resources/config/routing.yml
    prefix: /api/json-rpc/

Usage

Class annotation:

use Solution\JsonRpcBundle\Annotation as Api;
/**
 * @Api\JsonRpcApi(service = "api", namespace="test-api")
 */

Method annotation:

    /**
     * @Api\JsonRpcMethod
     *
     * @param null $id
     * @return bool
     */
    public function getTemplate($id = null)
    {
        return [
            "id" => 83,
            "name" => "test"
        ];
    }

Post request example:

{"jsonrpc":"2.0","method":"test-api.getTemplate","params":[4],"id":"foo"}

Response example:

{"result":[{"id":83,"name":"test"}],"id":"foo","jsonrpc":"2.0"}

@todo

  • README
  • Add the ability to describe methods with auto gen SDM
  • write functional test