2017 © Pedro Peláez
 

library apigility-routeaccept

Routing based on Accept header for Apigility

image

zpetr/apigility-routeaccept

Routing based on Accept header for Apigility

  • Wednesday, May 4, 2016
  • by zpetr
  • Repository
  • 1 Watchers
  • 1 Stars
  • 48 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

apigility-routeaccept

Routing based on Accept header of request, (*1)


This module give you possibility to have any number of APIs with the same 'route' name., (*2)

Example:

Imagine that you have API car and API moto. If you create route named brand for both APIs, apigility will redirect you always to the last one. RouteAccept module offer a possibility to use API which correspond to the Accept Header., (*3)

So,, (*4)

  • request to /brand with Accept header "application/vnd.car.v1+json" will give you something like:
{
    "brand": [
        {
            "id": 1,
            "name": "BMW"
        },
        {
            "id": 2,
            "name": "Ford"
        },
        ...
    ]
}
  • request to /brand with Accept header "application/vnd.moto.v1+json" will give you something like:
{
    "brand": [
        {
            "id": 1,
            "name": "Harley-Davidson"
        },
        {
            "id": 2,
            "name": "Kawasaki"
        },
        ...
    ]
}

Installation

Install composer in your project, (*5)

curl -s http://getcomposer.org/installer | php

Define dependencies in your composer.json file, (*6)

{
    "require": {
        "zpetr/apigility-routeaccept" : "1.*"
    }
}

Finally install dependencies, (*7)

php composer.phar install

or update it, (*8)

php composer.phar update

Usage

  • Add zPetr\RouteAccept to config/modules.config.php:
    return array(
        'modules' => array(
            ...,
            'zPetr\\RouteAccept',
            ....
        )
    )     
  • Create APIs and routes (you can use the same names for different routes now)
  • Use it!

The Versions

04/05 2016

dev-master

9999999-dev https://github.com/zpetr/apigility-routeaccept

Routing based on Accept header for Apigility

  Sources   Download

BSD

The Requires

 

by Petr Glushchenko

api zf2 route module apigility accept header