PHPackages                             erwin32/rest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. erwin32/rest

ActiveLibrary[HTTP &amp; Networking](/categories/http)

erwin32/rest
============

Rest client fork

0173PHP

Since Feb 8Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Erwin32/php-restclient)[ Packagist](https://packagist.org/packages/erwin32/rest)[ RSS](/packages/erwin32-rest/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP REST Client
===============

[](#php-rest-client)

(c) 2013 Travis Dent

Basic Usage
-----------

[](#basic-usage)

```
$api = new RestClient(array(
    'base_url' => "https://api.twitter.com/1.1",
    'format' => "json",
     // https://dev.twitter.com/docs/auth/application-only-auth
    'headers' => array('Authorization' => 'Bearer '.OAUTH_BEARER),
));
$result = $api->get("search/tweets", array('q' => "#php"));
// GET http://api.twitter.com/1.1/search/tweets.json?q=%23php
if($result->info->http_code == 200)
    var_dump($result->decode_response());

```

Configurable Options
--------------------

[](#configurable-options)

`headers` - An associative array of HTTP headers and values to be included in every request.
`parameters` - An associative array of parameters to be merged with individual request parameters in every request.
`curl_options` - cURL options to apply to every request. These will override any automatically generated values.
`user_agent` - User agent string.
`base_url` - URL to use for the base of each request.
`format` - Format to append to resource and support decoding.
`format_regex` - Pattern to extract format from response Content-Type header.
`decoders` - Associative array of format decoders, see documentation below.
`username` - Username to use for basic authentication. Requires `password`.
`password` - Password to use for basic authentication. Requires `username`.

Options can be set upon instantiation, or individually afterword:

```
$api = new RestClient(array(
    'format' => "json",
    'user_agent' => "my-application/0.1"
));

```

-or-

```
$api = new RestClient;
$api->set_option('format', "json");
$api->set_option('user_agent', "my-application/0.1");

```

Verbs
-----

[](#verbs)

Four HTTP verbs are implemented as convenience methods: `get()`, `post()`, `put()` and `delete()`. Each accepts three arguments:

`url` - URL of the resource you are requesting. Will be prepended with the value of the `base_url` option, if it has been configured. Will be appended with the value of the `format` option, if it has been configured.
`parameters` - An associative array of query parameters, which will be formatted with the URL in `GET` requests, and passed in the request body on all others.
`headers` - An associative array of headers to include with the request.

You can make a request using any verb by calling `execute()` directly, which accepts four arguments: `url`, `method`, `parameters` and `headers`. All arguments expect the same values as in the convenience methods, with the exception of the additional `method` argument:

`method` - HTTP verb to perform the request with.

Not all endpoints support all HTTP verbs
----------------------------------------

[](#not-all-endpoints-support-all-http-verbs)

These are examples of two common workarounds, but are entirely dependent on the endpoint you are accessing. Consult the service's documentation to see if this is required.

Passing an `X-HTTP-Method-Override` header:

```
$result = $api->post("put_resource", array(), array(
    'X-HTTP-Method-Override' => "PUT"
));

```

Passing a `_method` parameter:

```
$result = $api->post("put_resource", array(
    '_method' => "PUT"
));

```

Attributes populated after making a request
-------------------------------------------

[](#attributes-populated-after-making-a-request)

`response` - Plain text response body.
`headers` - Parsed response header object.
`info` - cURL response info object.
`error` - Response error string.

Direct Iteration and Response Decoding
--------------------------------------

[](#direct-iteration-and-response-decoding)

If the the response data format is supported, the response will be decoded and accessible by iterating over the returned instance. When the `format`option is set, it will be used to select the decoder. If no `format` option is provided, an attempt is made to extract it from the response `Content-Type`header. This pattern is configurable with the `format_regex` option.

```
$api = new RestClient(array(
    'base_url' => "http://vimeo.com/api/v2",
    'format' => "php"
));
$result = $api->get("tcdent/info");
foreach($result as $key => $value)
    var_dump($value);

```

Reading via ArrayAccess has been implemented, too:

```
var_dump($result['id']);

```

To access the decoded response as an array, call `decode_response()`.

'json' and 'php' formats are configured to use the built-in `json_decode`and `unserialize` functions, respectively. Overrides and additional decoders can be specified upon instantiation, or individually afterword. Decoder functions take one argument: the raw request body. Functions created with `create_function` work, too.

```
function my_xml_decoder($data){
    new SimpleXMLElement($data);
}

$api = new RestClient(array(
    'format' => "xml",
    'decoders' => array('xml' => "my_xml_decoder")
));

```

-or-

```
$api = new RestClient;
$api->set_option('format', "xml");
$api->register_decoder('xml', "my_xml_decoder");

```

Or, without polluting the global scope with a runtime function. This particular example allows you to receive decoded JSON data as an array.

```
$api->register_decoder('json',
    create_function('$a', "return json_decode(\$a, TRUE);"));

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d503dce9a2e3d66e6826f98383cb498038f45c0929f3707e237fe32bb4ee198d?d=identicon)[Erwin32](/maintainers/Erwin32)

---

Top Contributors

[![tcdent](https://avatars.githubusercontent.com/u/54419?v=4)](https://github.com/tcdent "tcdent (7 commits)")[![Erwin32](https://avatars.githubusercontent.com/u/4253182?v=4)](https://github.com/Erwin32 "Erwin32 (6 commits)")[![h4ng3r](https://avatars.githubusercontent.com/u/2039733?v=4)](https://github.com/h4ng3r "h4ng3r (1 commits)")

### Embed Badge

![Health badge](/badges/erwin32-rest/health.svg)

```
[![Health](https://phpackages.com/badges/erwin32-rest/health.svg)](https://phpackages.com/packages/erwin32-rest)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
