solution/json-rpc-bundle

Zend2 Json Rpc Server的包装器

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

This package is not auto-updated.

Last update: 2024-09-24 02:06:33 UTC


README

Symfony2 Bundle包装器,用于Zend JsonRpc Server

安装

solution/json-rpc-bundle添加到composer.json

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

SolutionJsonRpcBundle添加到你的AppKernel.php

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

配置

选择你想要通过注解使用json-rpc的包,以便包可以将其拾取,并将它们添加到你的依赖注入容器中

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

将路由添加到你的routing.yml

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

使用方法

类注解

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

方法注解

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

POST请求示例

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

响应示例

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

@todo

  • README
  • 添加使用自动生成SDM描述方法的能力
  • 编写功能测试