-
-
Save vrudikov/cbf2f5642886f006225c to your computer and use it in GitHub Desktop.
Example of modRest, a REST Client, in MODX 2.3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$config = array( | |
'baseUrl' => rtrim('http://mywebsite.com/rest/api/','/'), | |
'format' => 'json', // json or xml, the format to request | |
'suppressSuffix' => false, // if false, will append .json or .xml to the URI requested | |
'username' => 'myuser', // if set, will use cURL auth to authenticate user | |
'password' => 'mypass', | |
'curlOptions' => array( | |
'timeout' => 30, // cURL timeout | |
'otherCurlOption' => 1, | |
), | |
'headers' => array( | |
// any HTTP headers to be sent | |
), | |
'userAgent' => 'MODX RestClient/1.0.0', | |
'defaultParameters' => array( | |
'api_key' => 'if i want an api key passed always for every request', | |
'other_parameter' => 'these are always sent', | |
), | |
); | |
$client = new modRest($modx,$config); | |
// POST | |
$result = $client->post('people',array('name' => 'Joe')); | |
$response = $result->process(); | |
$id = $response['id']; | |
// PUT | |
$client->put('people/'.$id,array('name' => 'Joe','email' => 'joe@doe.com')); | |
$client->get('people',array('id' => $id)); | |
$client->delete('people/'.$id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment