paramoredigital/rest-request

A simple PHP class for submitting REST requests via cURL.

v1.3 2015-02-11 15:59 UTC

This package is not auto-updated.

Last update: 2024-11-23 18:30:41 UTC


README

A PHP class for submitting REST requests via cURL.

Configuration

Open the RestRequestConfig.php class and set the $baseUrl parameter to be the base URL of the API. Here, you can also set a default format for the request body (JSON or Form-encoded).

Usage

Define a new client like this:

$request = new \ParamoreDigital\RestRequest();

You can set cURL options like this:

$request->setHttpOptions(array(CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => 'username:password'));

You can set parameters like this:

$request->setParams(array('firstName' => 'Ben', 'lastName' => 'Wilkins'));

You can manually set an endpoint:

$request->setEndPoint('/some/endpoint');
$request->post();

Or, you can pass the endpoint straight into the action method:

$request->post('/some/endpoint');