Version: current

# Class RestfulService

RestfulService class allows you to consume various RESTful APIs. Through this you could connect and aggregate data of various web services. For more info visit wiki documentation - http://doc.silverstripe.org/doku.php?id=restfulservice

  Object
  ViewableData implements IteratorAggregate
  RestfulService

Package: sapphire\integration
Located at sapphire/api/RestfulService.php

## Methods summary

`public static` | # `set_default_proxy( string $proxy, integer $port = 80, string $user = "", string $password = "", boolean $socks = false )` Sets default proxy settings for outbound RestfulService connections Sets default proxy settings for outbound RestfulService connections #### Parameters $proxy string $proxy The URL of the proxy to use. $port int $port Proxy port $user string $user The proxy auth user name $password string $password The proxy auth password $socks boolean $socks Set true to use socks5 proxy instead of http
`public` | # `__construct( string $base, integer $expiry = 3600 )` Creates a new restful service. Creates a new restful service. #### Parameters $base string $base Base URL of the web service eg: api.example.com $expiry int $expiry Set the cache expiry interva. Defaults to 1 hour (3600 seconds) #### Overrides `Object::__construct`
`public` | # `setQueryString( array $params = NULL )` Sets the Query string parameters to send a request. Sets the Query string parameters to send a request. #### Parameters $params array $params An array passed with necessary parameters.
`public` | # `setProxy( string $proxy, integer $port = 80, string $user = "", string $password = "", boolean $socks = false )` Set proxy settings for this RestfulService instance Set proxy settings for this RestfulService instance #### Parameters $proxy string $proxy The URL of the proxy to use. $port int $port Proxy port $user string $user The proxy auth user name $password string $password The proxy auth password $socks boolean $socks Set true to use socks5 proxy instead of http
`public` | # `basicAuth( mixed $username, mixed $password )` Set basic authentication Set basic authentication
`public` | # `httpHeader( mixed $header )` Set a custom HTTP header Set a custom HTTP header
`protected` | # `constructURL( )`
`public` | # `connect( mixed $subURL = '' )` #### Deprecated Use RestfulService::request()
`public` | # `request( mixed $subURL = '', mixed $method = "GET", mixed $data = null, mixed $headers = null, mixed $curlOptions = array() )` Makes a request to the RESTful server, and return a `RestfulService_Response` object for parsing of the result. Makes a request to the RESTful server, and return a `RestfulService_Response` object for parsing of the result.
`public` | # `getAttributes( string $xml, string $collection = NULL, string $element = NULL )` Gets attributes as an array, of a particular type of element. Example : <photo id="2636" owner="123" secret="ab128" server="2"> returns id, owner,secret and sever attribute values of all such photo elements. Gets attributes as an array, of a particular type of element. Example : <photo id="2636" owner="123" secret="ab128" server="2"> returns id, owner,secret and sever attribute values of all such photo elements. #### Parameters $xml string $xml The source xml to parse, this could be the original response received. $collection string $collection The name of parent node which wraps the elements, if available $element string $element The element we need to extract the attributes.
`public` | # `getAttribute( string $xml, string $collection = NULL, string $element = NULL, string $attr )` Gets an attribute of a particular element. Gets an attribute of a particular element. #### Parameters $xml string $xml The source xml to parse, this could be the original response received. $collection string $collection The name of the parent node which wraps the element, if available $element string $element The element we need to extract the attribute $attr string $attr The name of the attribute
`public` | # `getValues( string $xml, string $collection = NULL, string $element = NULL )` Gets set of node values as an array. When you get to the depth in the hierachchy use node_child_subchild syntax to get the value. Gets set of node values as an array. When you get to the depth in the hierachchy use node_child_subchild syntax to get the value. #### Parameters $xml string $xml The the source xml to parse, this could be the original response received. $collection string $collection The name of parent node which wraps the elements, if available $element string $element The element we need to extract the node values.
`protected` | # `getRecurseValues( mixed $xml, mixed & $data, mixed $parent = "" )`
`public` | # `getValue( string $xml, string $collection = NULL, string $element = NULL )` Gets a single node value. Gets a single node value. #### Parameters $xml string $xml The source xml to parse, this could be the original response received. $collection string $collection The name of parent node which wraps the elements, if available $element string $element The element we need to extract the node value.
`public` | # `searchValue( string $xml, string $node = NULL )` Searches for a node in document tree and returns it value. Searches for a node in document tree and returns it value. #### Parameters $xml string $xml source xml to parse, this could be the original response received. $node string $node Node to search for
`public` | # `searchAttributes( string $xml, string $node = NULL )` Searches for a node in document tree and returns its attributes. Searches for a node in document tree and returns its attributes. #### Parameters $xml string $xml the source xml to parse, this could be the original response received. $node string $node Node to search for

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `CurrentPage()`, `Debug()`, `Even()`, `EvenOdd()`, `First()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Last()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `TotalItems()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getIterator()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `hasValue()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `exists()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected mixed` | $baseURL | #
`protected mixed` | $queryString | #
`protected mixed` | $errorTag | #
`protected mixed` | $checkErrors | #
`protected mixed` | $cache_expire | #
`protected mixed` | $authUsername | #
`protected mixed` | $authPassword | #
`protected array` | $customHeaders | #
`protected mixed` | $proxy | #
`protected static mixed` | $default_proxy | #

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -