paramoredigital / rest-request
A simple PHP class for submitting REST requests via cURL.
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-12-21 19:04:55 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');