Overview

Namespaces

  • Antavo
    • RestClient
      • Exceptions
    • SignedToken
      • Exceptions
  • PHP

Classes

  • RestClient
  • Overview
  • Namespace
  • Class

Class RestClient

A rather straightforward and lightweight, yet flexible helper class to perform operations on a RESTful API with cURL.

Direct known subclasses

Antavo\ApiClient
Namespace: Antavo\RestClient
Located at rest-client/src/RestClient.php
Methods summary
public mixed
# call( string $method, string $url, array|string $data = NULL, array $curl_options = array() )

Performs an API request.

Performs an API request.

Parameters

$method
HTTP method to use.
$url

URL to send request to. It is prefixed with the base_url unless it starts with a URL scheme.

$data

Data to send with request. It is sent as a request entity where allowed, or appended as a query string otherwise.

$curl_options

Additional cURL options for current request only.

Returns

mixed

Throws

Antavo\RestClient\Exceptions\Exception

If an error occurred during processing response.

public string
# getBaseUrl( )

Returns base URL prepended to relative URL's for each request.

Returns base URL prepended to relative URL's for each request.

Returns

string
public Antavo\RestClient\Exceptions\Exception
# getLastError( )

Returns the last error occurred during processing the response.

Returns the last error occurred during processing the response.

Returns

Antavo\RestClient\Exceptions\Exception

Returns NULL if there was no error.

public mixed
# getLastResult( )

Returns body of last response, parsed according to Content-Type header.

Returns body of last response, parsed according to Content-Type header.

Returns

mixed
public string
# getLastResultHeaders( )

Returns headers of last response.

Returns headers of last response.

Returns

string
public array
# getLastResultInfo( )

Returns info on last request.

Returns info on last request.

Returns

array
For details see PHP curl_getinfo() manual.

Link

PHP: curl_getinfo - Manual
public
# setCurlOption( string $option, mixed $value = NULL )

Appends cURL option to defaults.

Appends cURL option to defaults.

Parameters

$option
Option name. See cURL options for option names.
$value

Option value. Providing a NULL removes an already set option.

Link

List of cURL options.
public
# setCurlOptions( array $options )

Appends multiple cURL options to defaults.

Appends multiple cURL options to defaults.

Parameters

$options

cURL options as key-value pairs. For keys and their values see cURL options. Providing a NULL value removes an already set option.

Link

List of cURL options.
public
# setBaseUrl( string $base_url )

Sets base URL which is to prepend to relative URL's for each request.

Sets base URL which is to prepend to relative URL's for each request.

Parameters

$base_url
public
# setError( Antavo\RestClient\Exceptions\Exception $exception = NULL )

Used to set an error without exiting the normal flow of an API call.

Used to set an error without exiting the normal flow of an API call.

Calling without argument or with a NULL value resets the stored last error.

Parameters

$exception

See

Antavo\RestClient\RestClient::getLastError()
Magic methods summary
public mixed
# get( string $url, mixed $data = NULL, array $curl_options = array() )

Performs a GET request to the API.

Performs a GET request to the API.

Parameters

$url
$data
$curl_options

Returns

mixed
public mixed
# post( string $url, mixed $data = NULL, array $curl_options = array() )

Performs a POST request to the API.

Performs a POST request to the API.

Parameters

$url
$data
$curl_options

Returns

mixed
public mixed
# put( string $url, mixed $data = NULL, array $curl_options = array() )

Performs a PUT request to the API.

Performs a PUT request to the API.

Parameters

$url
$data
$curl_options

Returns

mixed
public mixed
# delete( string $url, mixed $data = NULL, array $curl_options = array() )

Performs a DELETE request to the API.

Performs a DELETE request to the API.

Parameters

$url
$data
$curl_options

Returns

mixed
API documentation generated by ApiGen