2017 © Pedro Peláez
 

library laravel-negotiator

Content negotiation for Laravel API

image

mleczek/laravel-negotiator

Content negotiation for Laravel API

  • Saturday, January 21, 2017
  • by mleczek
  • Repository
  • 1 Watchers
  • 1 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Content negotiation for Laravel API

Build Status Latest Stable Version License, (*1)

Installation

Require this package with composer:, (*2)

composer require mleczek/laravel-negotiator

In config/app.php add the NegotiatorServiceProvider:, (*3)

'providers' => [
    Mleczek\Negotiator\NegotiatorServiceProvider::class,
]

Usage

Package provide negotiate macro for ResponseFactory:, (*4)

public function show(User $user)
{
    return response()->negotiate($user);
}

The same result can be achieved using Mleczek\Negotiator\ContentNegotiation class:, (*5)

public function __construct(ContentNegotiation $cn)
{
    $this->cn = $cn;
}

public function show(Request $request, User $user)
{
    return $cn->negotiate($request, $user);
}

For both negotiate method and macro there is also one parameter which override result for specified content types:, (*6)

public function show(User $user)
{
    // Return static JSON for request which
    // contains "application/json" in "Accepts" header.
    return response()->negotiate($user, [
        'application/json' => '{"id":4}',
    ]);
}

By default package support application/json and application/xml. XML format is resolved using mleczek/xml package., (*7)

Extending

You can extend supported content types in boot method of any of your ServiceProvider:, (*8)

public function boot(ContentNegotiation $negotiator)
{
    // The ContentNegotiation facade is also available
    $negotiator->extend('application/json', function () {
        return new JsonHandler();
    });
}

The first parameter accept content type (or array of content types) for which the specified handler should be used., (*9)

Handler must implement the Mleczek\Negotiator\Contracts\ContentNegotiationHandler interface., (*10)

Contributing

Thank you for considering contributing! If you would like to fix a bug or propose a new feature, you can submit a Pull Request., (*11)

License

The library is licensed under the MIT license., (*12)

The Versions

21/01 2017

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/mleczek/laravel-negotiator

Content negotiation for Laravel API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Wojciech Mleczek

laravel xml content negotiation

21/01 2017

v1.0.1

1.0.1.0 https://github.com/mleczek/laravel-negotiator

Content negotiation for Laravel API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Wojciech Mleczek

laravel xml content negotiation

20/01 2017

dev-master

9999999-dev https://github.com/mleczek/laravel-negotiator

Content negotiation for Laravel API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Wojciech Mleczek

laravel xml content negotiation