2017 © Pedro Peláez
 

library laravel-restclient

Simple RestClient for Laravel 4

image

nathanmac/laravel-restclient

Simple RestClient for Laravel 4

  • Monday, January 16, 2017
  • by nathanmac
  • Repository
  • 2 Watchers
  • 30 Stars
  • 2,609 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 18 Forks
  • 3 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

laravel-restclient

Build Status Still Maintained, (*1)

Simple RestClient Package for Laravel 4, (*2)

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require Nathanmac/laravel-restclient., (*3)

"require": {
    "nathanmac/laravel-restclient": "dev-master"
}

Next, update Composer from the Terminal:, (*4)

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., (*5)

'Nathanmac\RestClient\RestClientServiceProvider'
Calling an Endpoint
try {
    $response = RestClient::get('hostname:port/endpoint');
} catch (Exception $ex) {
    print "Error: " . $ex->getMessage(); // Error: COULDNT_RESOLVE_HOST
}
HTTP Methods
  $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');
Adding HTTP Headers
$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);
Get the HTTP Status Code
echo "HTTP Status Code: " . $response->getStatusCode(); // HTTP Status Code: 200
echo "HTTP Status Text: " . $response->getStatusText(); // HTTP Status Text: OK
Returning the response content
print $response->getContent();
Returning the response headers
print_r($response->getHeaders());
Returning a specific header
echo "Content-Type: " . $response->getHeader('content_type'); // Content-Type: application/json
Returning the response time (seconds)
echo "Time: " . $response->getTime();  // Time: 0.23453
Adding custom cURL options for every request

At the beginning publish the config file:, (*6)

php artisan config:publish nathanmac/laravel-restclient

Then edit the options array in app/config/packages/nathanmac/laravel-restclient/config.php., (*7)

The Versions

16/01 2017

dev-master

9999999-dev

Simple RestClient for Laravel 4

  Sources   Download

MIT

The Requires

 

by Nathan Macnamara