VERSION
VERSION
The version of this lib
A simple PHP library for doing RESTful HTTP stuff. Does not require the curl extension.
__construct(array $opts)
Class constructor
Passed opts
can include:
array | $opts | OPTIONAL array of options |
get(string $url, array|string $querydata, array $headers, array $options) : array
make a GET request
string | $url | the URL. This will be appended to the base_url, if any set |
array|string | $querydata | hash of key/val pairs. This will be appended to the URL |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
post(string $url, array|string $querydata, array $headers, array $options) : array
make a POST request
string | $url | the URL. This will be appended to the base_url, if any set |
array|string | $querydata | hash of key/val pairs. This will be sent in the request body |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
put(string $url, array|string $querydata, array $headers, array $options) : array
make a PUT request
string | $url | the URL. This will be appended to the base_url, if any set |
array|string | $querydata | hash of key/val pairs. This will be sent in the request body |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
patch(string $url, array|string $querydata, array $headers, array $options) : array
make a PATCH request
string | $url | the URL. This will be appended to the base_url, if any set |
array|string | $querydata | hash of key/val pairs. This will be sent in the request body |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
delete(string $url, array|string $querydata, array $headers, array $options) : array
make a DELETE request
string | $url | the URL. This will be appended to the base_url, if any set |
array|string | $querydata | hash of key/val pairs. This will be appended to the URL |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
postJson(string $url, array|\Resty\stdClass $structure, array $headers, array $options) : array
make a POST request with a JSON body.
The Content-Type header will be set to 'application/json'
string | $url | the URL. This will be appended to the base_url, if any set |
array|\Resty\stdClass | $structure | the array or object to send as JSON |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
putJson(string $url, array|\Resty\stdClass $structure, array $headers, array $options) : array
make a PUT request with a JSON body.
The Content-Type header will be set to 'application/json'
string | $url | the URL. This will be appended to the base_url, if any set |
array|\Resty\stdClass | $structure | the array or object to send as JSON |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
patchJson(string $url, array|\Resty\stdClass $structure, array $headers, array $options) : array
make a PATCH request with a JSON body.
The Content-Type header will be set to 'application/json'
string | $url | the URL. This will be appended to the base_url, if any set |
array|\Resty\stdClass | $structure | the array or object to send as JSON |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
postFiles(string $url, array $files, array $params, array $headers, array $options) : array
POST one or more files
The $files array should be a set of key/val pairs, with the key being the field name, and the val the file path. ex: $files['avatar'] = '/path/to/file.jpg'; $files['background'] = '/path/to/file2.jpg';
string | $url | |
array | $files | |
array | $params | |
array | $headers | |
array | $options |
postBinary(string $url, array $binary_data, array $params, array $headers, array $options) : array
POST binary data directly, without reading from file(s)
The $binary_data array should be a set of key/val pairs, with the key being
the field name, and the val the binary data. ex:
$files['avatar'] =
with that data, a multipart POST body is created, identical to a file upload, just without reading the data from a file
string | $url | |
array | $binary_data | |
array | $params | |
array | $headers | |
array | $options |
supportsPatch(boolean $state) : boolean
configure whether or not the REST endpoint supports the HTTP PATCH method. If set to false, the X-HTTP-Method-Override header will be sent using HTTP POST.
boolean | $state | = null optional, set the state |
the current state
sendRequest(string $url, string $method, array|string $querydata, array $headers, array $options) : array
Sends the HTTP request and retrieves/parses the response
string | $url | |
string | $method | |
array|string | $querydata | OPTIONAL |
array | $headers | OPTIONAL |
array | $options | OPTIONAL |
sendJsonRequest(string $url, string $method, array|\Resty\stdClass $structure, array $headers, array $options) : array
A wrapper for Resty::sendRequest that encodes the $structure as JSON and sets the Content-Type header will be set to 'application/json'
string | $url | the URL. This will be appended to the base_url, if any set |
string | $method | the HTTP method. This should really only be (POST|PUT|PATCH) |
array|\Resty\stdClass | $structure | the array or object to send as JSON |
array | $headers | hash of key/val pairs |
array | $options | hash of key/val pairs ('timeout') |
the response hash
getMimeType(string $filepath)
Stole this from the Amazon S3 class:
Copyright (c) 2008, Donovan Schönknecht. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Amazon S3 is a trademark of Amazon.com, Inc. or its affiliates.
string | $filepath | the path to the file |