jpierront/api-batch-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jpierront/api-batch-bundle

最新稳定版本:v1.0.0

Composer 安装命令:

composer require jpierront/api-batch-bundle

包简介

Api Batch Bundle

README 文档

README

About

The JPierrontApiBatchBundle allows you to send multiple JSON api call in only one http request.

Installation

Require the jpierront/api-batch-bundle package in your composer.json and update your dependencies.

$ composer require jpierront/api-batch-bundle

Add the JPierrontApiBatchBundle to your application's kernel:

public function registerBundles()
{
    $bundles = array(
        ...
        new JPierront\ApiBatchBundle\JPierrontApiBatchBundle(),
        ...
    );
    ...
}

Configuration

Create a route for the batch action

YAML:

# app/config/routing.yml
batch:
    path:   /api/batch
    defaults:  { _controller: JPierrontApiBatchBundle:ApiBatch:apiBatch }

Annotation:

# app/config/routing.yml
batch:
    resource: AppBundle\Controller\ApiBatchController
    
// AppBundle\Controller\ApiBatchController.php
class ApiBatchController extends BaseApiBatchController
{
    /**
     * @Route(path="batch", name="batch")
     */
    public function getAction(Request $request)
    {
        return parent::getAction($request);
    }
}

Usage

Request

Call your new batch api in POST method with JSON in request body

[
    {
        "method": "GET",
        "url": "/sub-api-1",
        "parameters": "queryParameter1=value1&queryParameter2=value2"
    },
    {
        "method": "POST",
        "url": "/sub-api-2",
        "parameters": "postParameter1=value1&postParameter2=value2"
    }
]

method

  • Accept any HTTP method (GET, POST, PUT, PATCH, ...)
  • Must be equal to the method expected by your api

url

  • Relative url of your sub api
  • Without the hostname
  • Without the query parameters

parameters

  • You GET or POST parameters formatted like query string

Response

The batch api will return a JSON response

[
    {
        "code": 200,
        "headers": {
            "content-type": "application\/json",
        },
        "body": "Your json response of sub api 1"
    },
    {
        "code": 200,
        "headers": {
            "content-type": "application\/json",
        },
        "body": "Your json response of sub api 2"
    }
]

code

  • Is the http status code of the sub api call

headers

  • Is the headers of the sub api call

body

  • Is the body of the sub api call

License

Released under the MIT License, see LICENSE.

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-16