2017 © Pedro Peláez
 

library api-batch-bundle

Api Batch Bundle

image

jpierront/api-batch-bundle

Api Batch Bundle

  • Wednesday, September 16, 2015
  • by jpierront
  • Repository
  • 0 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

JPierrontApiBatchBundle

About

The JPierrontApiBatchBundle allows you to send multiple JSON api call in only one http request., (*1)

Installation

Require the jpierront/api-batch-bundle package in your composer.json and update your dependencies., (*2)

$ composer require jpierront/api-batch-bundle

Add the JPierrontApiBatchBundle to your application's kernel:, (*3)

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

Configuration

Create a route for the batch action, (*4)

YAML:, (*5)

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

Annotation:, (*6)

# 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, (*7)

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

method, (*8)

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

url, (*9)

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

parameters, (*10)

  • You GET or POST parameters formatted like query string

Response

The batch api will return a JSON response, (*11)

[
    {
        "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, (*12)

  • Is the http status code of the sub api call

headers, (*13)

  • Is the headers of the sub api call

body, (*14)

  • Is the body of the sub api call

License

Released under the MIT License, see LICENSE., (*15)

The Versions

16/09 2015

dev-master

9999999-dev https://github.com/jpierront/ApiBatchBundle

Api Batch Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien Pierront

16/09 2015

dev-feat-refactor

dev-feat-refactor https://github.com/jpierront/ApiBatchBundle

Api Batch Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien Pierront

16/09 2015

v1.0.0

1.0.0.0 https://github.com/jpierront/ApiBatchBundle

Api Batch Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien Pierront