Download the PHP package sobolan/rest-negotiator without Composer
On this page you can find all versions of the php package sobolan/rest-negotiator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sobolan/rest-negotiator
More information about sobolan/rest-negotiator
Files in sobolan/rest-negotiator
Package rest-negotiator
Short Description A library that allows negotiating content in your REST Webservices
License MIT
Informations about the package rest-negotiator
Purpose
This library is useful when you want to version your Symfony-based REST API by relying on the Accept (for output) and Content-Type (for input) HTTP headers.
The library does all this by building on top of the powerful Symfony Serializer component.
Same data in different format
For example: let's say in your application you ask for information about a user and you also specify the required Accept header:
You get something like this:
However, let's say your mobile app only knows how to read/interpret XML content. Therefore, all you have to do is change the value of the format parameter:
Now you get something like this:
Same data, different format ;) . And, as you will see, it will require ZERO extra lines of code in your application.
Supporting different response structures at the same time
Let's say at some point you don't want this route to return the user-ID anymore, since it's a value that is internal to your system.
You could just remove it. But all your iOS/Android/desktop clients rely on it. If you remove it, these applications will break.
Instead, you could just use this library and have it support responses both with the user-ID and without. This is what the version parameter is for:
Response:
If you use a different version, let's say "2", you can have the API do this:
Response:
Notice how the "id" field is missing. This is extremely easy to do with this library.
After you do this, all you have to do is gradually (and on your own time) migrate your clients to using version "2" of your API.
When you're done, just bump the default version of the API so that "id" doesn't show up by default and you're done !
No more stressful syncing of deployments and no more nightmares of clients that might or might not break ;)
How to use it
A complete documentation about how to use the library can be found here: /doc/howtouse.md.
Please note that it may be trickier or more difficult to implement in the beginning. But it will feel more natural once you get used to it and its features.
Complete Example
A complete example that uses the library can be found here: sobolan/rest-negotiator-example.
License
This library is published under the MIT license.
All versions of rest-negotiator with dependencies
ext-json Version *
symfony/serializer Version ~2.8|~3.0
symfony/yaml Version ~2.8|~3.0
symfony/routing Version ~2.8|~3.0
symfony/config Version ~2.8|~3.0
symfony/http-kernel Version ~2.8|~3.0
symfony/dependency-injection Version ~2.8|~3.0
symfony/http-foundation Version ~2.8|~3.0