PHPackages                             gino-pane/nano-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. gino-pane/nano-rest

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

gino-pane/nano-rest
===================

Minimalistic and self-contained cURL HTTP REST client for PHP

v1.2.3(8y ago)320111MITPHPPHP ^7.1

Since Nov 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/GinoPane/php-nano-rest)[ Packagist](https://packagist.org/packages/gino-pane/nano-rest)[ Docs](https://github.com/GinoPane/php-nano-rest)[ RSS](/packages/gino-pane-nano-rest/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (12)Used By (1)

PHP Nano Rest
=============

[](#php-nano-rest)

[![Latest Stable Version](https://camo.githubusercontent.com/c1aec54989a06484a64e4972df8ae23a07f2f657aaa5619eacc51c983cb3e147/68747470733a2f2f706f7365722e707567782e6f72672f67696e6f2d70616e652f6e616e6f2d726573742f762f737461626c65)](https://packagist.org/packages/gino-pane/nano-rest)[![Build Status](https://camo.githubusercontent.com/49fcbaf1da69edd8ed8adf3f85b68053032fbe1b93ff8d385f107d20d2baa1b4/68747470733a2f2f7472617669732d63692e6f72672f47696e6f50616e652f7068702d6e616e6f2d726573742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/GinoPane/php-nano-rest)[![Maintainability](https://camo.githubusercontent.com/561d2f0bb45a1473431415a06052a28a3df61135edb5459d6796d7661f05cc0b/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66383763663065656638616164393963343838632f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/GinoPane/php-nano-rest/maintainability)[![Test Coverage](https://camo.githubusercontent.com/1b34d0144e3676e069c33405606a622cd41769acb313420ba82c0a8afec38d88/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66383763663065656638616164393963343838632f746573745f636f766572616765)](https://codeclimate.com/github/GinoPane/php-nano-rest/test_coverage)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/396029e86125189ac3c4898fcbbbe4a3bde99fdf3ebd6f3177fd3e8ece236953/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f47696e6f50616e652f7068702d6e616e6f2d726573742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/GinoPane/php-nano-rest/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/d959882a4458813144924e674101ac14df748821aa140b70c42f4f8a71098e39/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f61333131323566312d666639372d343163392d623066312d3965366235656235383437302e737667)](https://insight.sensiolabs.com/projects/a31125f1-ff97-41c9-b0f1-9e6b5eb58470)[![License](https://camo.githubusercontent.com/357ec3dbb16c4f5fc523d1573f61adb25acb3102ae1f5de64491ae31a0b31c59/68747470733a2f2f706f7365722e707567782e6f72672f67696e6f2d70616e652f6e616e6f2d726573742f6c6963656e7365)](https://packagist.org/packages/gino-pane/nano-rest)[![Total Downloads](https://camo.githubusercontent.com/2788bee6cfb4bdee1cebfa013064accc9f13c345f5e80ac6cf3f5c40ea6661a6/68747470733a2f2f706f7365722e707567782e6f72672f67696e6f2d70616e652f6e616e6f2d726573742f646f776e6c6f616473)](https://packagist.org/packages/gino-pane/nano-rest)

Easy-to-use self-containing lightweight package to deal with cURL requests.

Such packages as [Guzzle](https://github.com/guzzle/guzzle) are great of course, but they are too heavy for small projects. You don't need an overkill package for some easy stuff, and that's when something small and neat may help.

Requirements
============

[](#requirements)

- PHP &gt;= 7.1;
- cURL extension.

Installation
============

[](#installation)

Require the package using command line:

```
composer require "gino-pane/nano-rest:1.*"

```

or just put a new dependency in your existing `composer.json` and run `composer install` after that:

```
"require": {
    ...
    "gino-pane/nano-rest": "1.*"
}

```

Usage
=====

[](#usage)

Project's philosophy implies usage of `RequestContext` and `ResponseContext` objects. `RequestContext` aggregates request settings whilst `ResponseContext` contains response data.

Response context can be typed. Currently only `JsonResponseContext` available for JSON responses. Response type must be set explicitly by user. If no response type set, `DummyResponseContext` will be used.

Please take a look at examples below, which may clarify everything.

#### POST some data to endpoint

[](#post-some-data-to-endpoint)

```
require './vendor/autoload.php';

$nanoRest = new NanoRest();

//create request context
$requestContext = (new RequestContext('http://httpbin.org/post')) //pass URL to constructor
    ->setMethod(RequestContext::METHOD_POST) //set request method. GET is default
    ->setRequestParameters([ //set some request parameters. They will be attached to URL
        'foo' => 'bar'
    ])
    ->setData('Hello world!') //set request data for body
    ->setContentType(RequestContext::CONTENT_TYPE_TEXT_PLAIN) //being set by default
    ->setHeaders([ // set some headers for request
        'bar' => 'baz'
    ])
    ->setResponseContextClass(JsonResponseContext::class); //explicitly set expected response type

$responseContext = $nanoRest->sendRequest($requestContext);

$responseContext->getHttpStatusCode(); //200
$responseContext->hasHttpError() //false

$responseContext->getArray();

/**
array(8) {
  'args' =>
  array(1) {
    'foo' =>
    string(3) "bar"
  }
  'data' =>
  string(12) "Hello world!"
  'files' =>
  array(0) {
  }
  'form' =>
  array(0) {
  }
  'headers' =>
  array(8) {
    'Accept' =>
    string(3) "*/*"
    'Accept-Encoding' =>
    string(13) "deflate, gzip"
    'Bar' =>
    string(3) "baz"
    'Connection' =>
    string(5) "close"
    'Content-Length' =>
    string(2) "12"
    'Content-Type' =>
    string(25) "text/plain; charset=UTF-8"
    'Host' =>
    string(11) "httpbin.org"
    'User-Agent' =>
    string(13) "php-nano-rest"
  }
  'json' =>
  NULL
  'origin' =>
  string(12) "93.85.47.181"
  'url' =>
  string(31) "http://httpbin.org/post?foo=bar"
}
*/

```

`RequestContext` provides `setCurlOption`/`setCurlOptions` which allow to override default cURL options and customize request for all your needs. Please examine source code and provided `IntegrationTest` carefully to get the whole idea.

#### Change the way how request query is generated

[](#change-the-way-how-request-query-is-generated)

By default `http_build_query` encodes arrays using PHP square brackets syntax, like this:

```
?text[0]=1&text[1]=2&text[2]=3

```

But sometimes you'll want it to work like this instead:

```
?text=1&text=2&text=3

```

Or even in some other custom-defined way.

That's why `setEncodeArraysUsingDuplication` and `setHttpQueryCustomProcessor` methods were added to `RequestContext`:

```
$url = "http://some.url";
$data = ['text' => [1,2,3]];

$request = (new RequestContext($url))
            ->setRequestParameters($data)
            ->setEncodeArraysUsingDuplication(false);

$requestUrl = $request->getRequestUrl(); //http://some.url?text%5B0%5D=1&text%5B1%5D=2&text%5B2%5D=3

$request = (new RequestContext($url))
            ->setRequestParameters($data)
            ->setEncodeArraysUsingDuplication(true);

$requestUrl = $request->getRequestUrl(); //http://some.url?text=1&text=2&text=3

```

Method `setHttpQueryCustomProcessor` allows you to set your custom `Closure` that will be called on HTTP query string so you could process it as you wish. Initial request `$data` array will be passed to it as a second parameter.

```
$url = "http://some.url";
$data = ['text' => [1,2,3]];

$request = (new RequestContext($url))
            ->setRequestParameters($data)
            ->setEncodeArraysUsingDuplication(true);

$request->setHttpQueryCustomProcessor(
    function (string $query, array $data) {
        return str_replace('text', 'data', $query);
    }
);

$requestUrl = $request->getRequestUrl(); //http://some.url?data=1&data=2&data=3

```

Useful Tools
============

[](#useful-tools)

Running Tests:
--------------

[](#running-tests)

```
php vendor/bin/phpunit

```

or

```
composer test

```

Code Sniffer Tool:
------------------

[](#code-sniffer-tool)

```
php vendor/bin/phpcs --standard=PSR2 src/

```

or

```
composer psr2check

```

Code Auto-fixer:
----------------

[](#code-auto-fixer)

```
php vendor/bin/phpcbf --standard=PSR2 src/

```

or

```
composer psr2autofix

```

Building Docs:
--------------

[](#building-docs)

```
php vendor/bin/phpdoc -d "src" -t "docs"

```

or

```
composer docs

```

Updating Cacert.pem:
--------------------

[](#updating-cacertpem)

```
    php bin/update-cacert.php

 or

    composer update-cacert

```

Changelog
=========

[](#changelog)

To keep track, please refer to [CHANGELOG.md](https://github.com/GinoPane/php-nano-rest/blob/master/CHANGELOG.md).

Contributing
============

[](#contributing)

Please refer to [CONTRIBUTING.md](https://github.com/GinoPane/php-nano-rest/blob/master/CONTRIBUTING.md).

License
=======

[](#license)

Please refer to [LICENSE](https://github.com/GinoPane/php-nano-rest/blob/master/LICENSE).

Notes
=====

[](#notes)

Powered by [composer-package-template](https://github.com/GinoPane/composer-package-template)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~8 days

Recently: every ~15 days

Total

11

Last Release

3007d ago

Major Versions

v0.1.0 → v1.0.02017-11-30

PHP version history (2 changes)v0.1.0PHP ^7.0

v1.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/13784bcc3c69ea265648475d67e70d2fdb427207ba73f140ff29b1ff00e3e3ef?d=identicon)[GinoPane](/maintainers/GinoPane)

---

Top Contributors

[![GinoPane](https://avatars.githubusercontent.com/u/3897579?v=4)](https://github.com/GinoPane "GinoPane (18 commits)")

---

Tags

curl-libraryhttp-clientphpphp-nano-resthttpresthttp clientrest-clientminimalisticphp restnano rest

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gino-pane-nano-rest/health.svg)

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

###  Alternatives

[slimpay/hapiclient

An HTTP Client using HAL as the format for resources.

14317.3k](/packages/slimpay-hapiclient)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11259.2k](/packages/e-moe-guzzle6-bundle)

PHPackages © 2026

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