Download the PHP package m6web/restconnection without Composer
On this page you can find all versions of the php package m6web/restconnection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download m6web/restconnection
More information about m6web/restconnection
Files in m6web/restconnection
Package restconnection
Short Description PHP class used to make requests to REST APIs easily.
License
Informations about the package restconnection
This repo is published "as is" from the 1.0.0
tarball of the deleted original at https://github.com/oziks/RESTConnection
You can use this package by requiring m6web/restconnection
, any of your dependencies should then use it as we're replacing the original.
Original README content below
RESTConnection is a PHP class used to make requests to REST APIs easily
About
The process is as follow :
-
instantiate a Client object, passing it the general parameters to connect to the REST api of your choice. ie : base url to the service, credentials, headers (to specify sent and accepted content types for example)
-
Use the method "request()" to send a request to this api, using parameters : url path, (optional) data to send, and method (verb, ie : get, post, put...) to use.
- Get the resulting http status code, body, header, error message
Altough RESTConnection supports most used http verbs (get, post, put, delete, patch), you might be in a situation where only get/post are supported (your firewall might block other verbs). In that case, you can set the compatibilityMode to true. Then, every delete, put, patch verb will be passed as a POST and a special header X-HTTP-Method-Override will be added. On another hand, you also might want to force this for one specific request. Think of google translate, that usually takes the word to translate as a GET. If you want to transalte a whole paragraph you'll have to pass it as a POST and force the X-HTTP-Method-Override to GET. You can do this easily, by just adding a overriding verb to the request parameters list.
Examples
Get twitter public tweets
Post a message to campfire, highlight it and then change the room topic
Credits
This code is partially based on this article : http://www.gen-x-design.com/archives/making-restful-requests-in-php/. Thanks to its author.