https://github.com/simplecomplex/restmini
Small powerful REST client
https://github.com/simplecomplex/restmini
chainable-methods php php7 psr rest rest-client
Last synced: 5 months ago
JSON representation
Small powerful REST client
- Host: GitHub
- URL: https://github.com/simplecomplex/restmini
- Owner: simplecomplex
- License: mit
- Created: 2016-09-17T13:36:17.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-02T10:06:19.000Z (almost 6 years ago)
- Last Synced: 2025-07-19T10:42:29.146Z (11 months ago)
- Topics: chainable-methods, php, php7, psr, rest, rest-client
- Language: PHP
- Size: 59.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.txt
- License: LICENSE
Awesome Lists containing this project
README
## RestMini Client ##
### Simple HTTP client ###
with chainable methods.
Highly configurable.
Extensive error handling and logging.
[cURL](https://curl.haxx.se)-based.
### Example ###
```php
use SimpleComplex\RestMini\Client;
// Get JSON-decoded response data.
$data = Client::make('http://server', '/endpoint', [
'headers' => [
'X-Whatever' => 'Hello',
],
'json_parse_assoc' => true,
])->get(
[
'some-path-arg' => 'foo',
],
[
'some-query-arg' => 'bar',
]
)->result();
// Check status first.
$response = Client::make('http://server', '/endpoint')->get();
if ($response->status() == 200) {
$data = $response->result();
}
else {
$info = $response->info();
$container = \SimpleComplex\Utils\Dependency::container();
$container->get('logger')->warning("Darned:\n" . json_encode($info, JSON_PRETTY_PRINT));
}
// Get raw response data.
$raw = Client::make('http://server', '/endpoint')->get()->raw():
```
### Client options ###
- (obj) **logger**: PSR-3 logger; otherwise checks in Utils\Dependency.
- (bool) **parse_json_assoc**: parse objects to associative arrays;
ignored if using the parser() method
- (str) **accept**
- (str) **accept_charset**
- (str) **content_type**: of request body; default application/json; supported:
''|application/json[; charset=some-charset]|application/x-www-form-urlencoded
- (int) **connect_timeout**: default 5 (seconds);
class constant CONNECT_TIMEOUT_DEFAULT
- (int) **request_timeout**
- (bool) **ssl_verify**: default true;
class constant SSL_VERIFY_DEFAULT
- (str) **ssl_cacert_file**: use custom CA cert file instead the common file
- (bool) **status_vain_result_void**: ~ result() returns empty string if
status >=300; suppress error messages etc. received in response body
- (bool) **ignore_status**: ~ don't trust response status code;
like 200 might actually be 404
- (bool) **ignore_content_type**: ~ don't trust response content type;
HTML might actually be JSON, and vice versa
- (str) **auth**: 'basic' or 'ntlm'; defaults to 'basic' if option _user_
- (str) **user**: for auth
- (str) **pass**: for auth
- (arr) **headers**: request headers
- (bool) **get_headers**: get response headers
- (int) **log_severity**: severity level when logging any error type except
logical error and (runtime) configuration error; default warning;
class constant LOG_SEVERITY_DEFAULT
- (string) **log_type**: use that log type when logging; default 'restmini_client';
class constant LOG_TYPE_DEFAULT
- (bool) **service_response_info_wrapper**: tell service to wrap response
in object listing service response properties
- (bool) **record_args**: make path+query+body args available after request
### Requirements ###
- PHP >=7.0
- PHP cURL extension
- [PSR-3 Log](https://github.com/php-fig/log)
- [SimpleComplex Inspect](https://github.com/simplecomplex/inspect)
- [SimpleComplex Utils](https://github.com/simplecomplex/php-utils)