TITAN Library for PHP5  5.6.0
Web Software Development Kit for PHP5
rest Class Reference

Titan REST API Request Class. More...

Public Member Functions

login ($username, $apikey)
 
format ($format)
 
request_as ($format)
 
response_as ($format)
 
 get ($url)
 
 post ($fields, $url, $format= '', $request= 'POST')
 
 put ($fields, $url, $format= '')
 
 delete ($url)
 

Detailed Description

Titan REST API Request Class.

Class: \tl\http\rest

Author
James E. Bush work@.nosp@m.bush.nosp@m..cc
Version
5.6.0

Example:

//  Setup
$rest = (new \tl\http\rest())->login($username, $apikey);     //  default format is JSON

//  OR, the more traditional setup
$rest = new \tl\http\rest();
$rest->login($username, $apikey);                             //  default format is JSON

//  RESTful GET
$response = $rest->get('http://api.domain.com/object/list');
$response = $rest->get('http://api.domain.com/object/' . $ObjectID);

//  RESTful DELETE
$response = $rest->delete('http://api.domain.com/object/' . $ObjectID);

//  RESTful POST      //  requires data as array or object
$response = $rest->post($object, 'http://api.domain.com/object/' . $ObjectID);

//  RESTful PUT       //  requires data as array or object
$response = $rest->put($object, 'http://api.domain.com/object/' . $ObjectID);

//  $response will be boolean FALSE or a PHP Object (the JSON or XML response will be decoded)

Member Function Documentation

& login (   $username,
  $apikey 
)

Set the username and apikey to use for all requests.

Parameters
string$username
string$apikey
Returns
$this
& format (   $format)

Set the format of the RESTful requests and responses.

Parameters
string$format(option) 'JSON' (option) 'XML'
Returns
$this
& request_as (   $format)

Set the format of the RESTful requests.

Parameters
string$format(option) 'JSON' (option) 'XML'
Returns
$this
& response_as (   $format)

Set the format of the RESTful responses.

Parameters
string$format(option) 'JSON' (option) 'XML'
Returns
$this
get (   $url)

Perform a RESTful GET

Parameters
string$urlThe RESTful API URL to GET
post (   $fields,
  $url,
  $format = '',
  $request = 'POST' 
)

Perform a RESTful POST

Parameters
mixed$fieldsAn array or object of data fields to POST
string$urlThe RESTful API URL to POST
string$format(optional) The data format to use for the request. You may either supply a $format or call $this->request_as($format) first. (default) '' = Use the value set by $this->request_as($format); or default to JSON. (option) 'JSON' (option) 'XML' ` *
string$request(optional) The HTTP request type. (default) 'POST' (option) 'POST' (option) 'PUT'
put (   $fields,
  $url,
  $format = '' 
)

Perform a RESTful PUT

Parameters
mixed$fieldsAn array or object of data fields to PUT
string$urlThe RESTful API URL to PUT
string$format(optional) The data format to use for the request. You may either supply a $format or call $this->request_as($format) first. (default) '' = Use the value set by $this->request_as($format); or default to JSON. (option) 'JSON' (option) 'XML'
delete (   $url)

Perform a RESTful DELETE

Parameters
string$urlThe RESTful API URL to DELETE

The documentation for this class was generated from the following file: