Skip to content

hexencoded/laravel-restclient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laravel-restclient

Build Status Still Maintained

Simple RestClient Package for Laravel 4

Installation

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'
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');
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

About

Simple RestClient Package for Laravel 4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%