-
Notifications
You must be signed in to change notification settings - Fork 0
06_learn_more__00_rest_client
Mako includes a basic REST that client makes it easy to interact with RESTful web services.
First you'll need to create a Rest object. Use the optional options parameter to set CURL options.
$rest = new Rest('http://example.org/api');
$rest = new Rest('http://example.org/api', array(CURLOPT_CONNECTTIMEOUT => 1));
If you need to provide authentication then you can use the authenticate method.
$rest->authenticate('username', 'password');
The get method performs a GET request and returns the response.
$response = $rest->get();
The head method performs a HEAD request and returns the response headers in a nicely formatted array.
$headers = $rest->head();
The post method performs a POST request and returns the response.
$movie = array
(
'title' => 'Thor',
'category' => 'Action',
);
$response = $rest->post($movie);
The put method performs a PUT request and returns the response.
$movie = array
(
'title' => 'Thor',
'category' => 'Action',
);
$response = $rest->put(json_encode($movie));
The delete method performs a DELETE request and returns the response.
$response = $rest->delete();
The info method returns info about the last cURL request.
$rest = new Rest('http://example.org/api');
$response = $rest->get();
if($rest->info('http_code') != 200)
{
// something went wrong
}
else
{
// everything is ok
}
You can also set the $info parameter offered by the request methods to save a few lines of code.
$response = Rest::factory('http://example.org')->get($info);
if($info['http_code'] != 200)
{
// something went wrong
}
else
{
// everything is ok
}
- Getting started: Installation
- Getting started: Configuration
- Getting started: Error handling
- Getting started: Constants
- Getting started: Coding standards
- Controllers: Controllers
- Controllers: Request
- Controllers: Response
- Databases: Basics
- Databases: Query builder
- Databases: Orm
- Databases: Migrations
- Command line: Basics
- Command line: Custom tasks
- Packages: Basics
- Packages: Composer packages
- Learn more: Array helper
- Learn more: Asset manager
- Learn more: Autoloading
- Learn more: Caching
- Learn more: Cookies
- Learn more: Events
- Learn more: File helper
- Learn more: Html helper
- Learn more: Internationalization
- Learn more: Logging
- Learn more: Number helper
- Learn more: Pagination
- Learn more: Redis client
- Learn more: Rest client
- Learn more: Security helpers
- Learn more: Sessions
- Learn more: String helper
- Learn more: Url helper
- Learn more: Uuid helper
- Learn more: Validation
- Learn more: Views