Package Data | |
---|---|
Maintainer Username: | nathanmac |
Maintainer Contact: | nathan.macnamara@arrowecs.co.uk (Nathan Macnamara) |
Package Create Date: | 2014-03-27 |
Package Last Update: | 2017-01-16 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-10 15:05:12 |
Package Statistics | |
---|---|
Total Downloads: | 3,169 |
Monthly Downloads: | 3 |
Daily Downloads: | 0 |
Total Stars: | 29 |
Total Watchers: | 3 |
Total Forks: | 17 |
Total Open Issues: | 2 |
Simple RestClient Package for Laravel 4
Begin by installing this package through Composer. Edit your project's composer.json
file to require Nathanmac/laravel-restclient
.
"require": {
"nathanmac/laravel-restclient": "dev-master"
}
Next, update Composer from the Terminal:
composer update
Once this operation completes, the final step is to add the service provider. Open app/config/app.php
, and add a new item to the providers array.
'Nathanmac\RestClient\RestClientServiceProvider'
try {
$response = RestClient::get('hostname:port/endpoint');
} catch (Exception $ex) {
print "Error: " . $ex->getMessage(); // Error: COULDNT_RESOLVE_HOST
}
$response = RestClient::get('hostname:port/endpoint');
$response = RestClient::post('hostname:port/endpoint', 'payload data');
$response = RestClient::put('hostname:port/endpoint', 'payload data');
$response = RestClient::delete('hostname:port/endpoint');
$headers = array(
'token: SLDKFJLKSDFJSLDFJ',
'other: asfasdfasdf'
);
$response = RestClient::get('hostname:port/endpoint', $headers);
$response = RestClient::post('hostname:port/endpoint', 'payload data', $headers);
$response = RestClient::put('hostname:port/endpoint', 'payload data', $headers);
$response = RestClient::delete('hostname:port/endpoint', $headers);
echo "HTTP Status Code: " . $response->getStatusCode(); // HTTP Status Code: 200
echo "HTTP Status Text: " . $response->getStatusText(); // HTTP Status Text: OK
print $response->getContent();
print_r($response->getHeaders());
echo "Content-Type: " . $response->getHeader('content_type'); // Content-Type: application/json
echo "Time: " . $response->getTime(); // Time: 0.23453
At the beginning publish the config file:
php artisan config:publish nathanmac/laravel-restclient
Then edit the options
array in app/config/packages/nathanmac/laravel-restclient/config.php
.