PHPackages                             nidux/niduxrest-php - 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. nidux/niduxrest-php

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

nidux/niduxrest-php
===================

A modern, fluent HTTP client. Forked from Mashape, reimagined by Nidux, and open-sourced for the PHP community.

v3.0.3(3w ago)03.7k↓23.1%MITPHPPHP &gt;=8.3CI passing

Since Jul 29Pushed 3w ago1 watchersCompare

[ Source](https://github.com/Nidux/NiduxRest)[ Packagist](https://packagist.org/packages/nidux/niduxrest-php)[ RSS](/packages/nidux-niduxrest-php/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (3)Versions (10)Used By (0)

NiduxRest PHP Client
====================

[](#niduxrest-php-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/41c539279a312448877de4f6c115086819c3b0e2baf596b067a1e05758c39e92/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e696475782f6e69647578726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nidux/niduxrest-php)[![GitHub Tests Action Status](https://camo.githubusercontent.com/4cd5de27404d3f05b4c679f7353b8e45a99f60a715cf56dc410264c2a7ec90d1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4e696475782f4e69647578526573742f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/Nidux/NiduxRest/actions)[![Total Downloads](https://camo.githubusercontent.com/a3676a05851bee94020b3afb8a0c19b1f2ebe751f384958e0c3e945cd53d31fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e696475782f6e69647578726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nidux/niduxrest-php)[![PHP from Packagist](https://camo.githubusercontent.com/9b95f713c7d0d1c7309a920df9007f85e2cda240bd4d8cbf08ab0dd0832f4cde/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e696475782f6e69647578726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nidux/niduxrest-php)

A fast, lightweight, and modern HTTP client for PHP 8.3+. Originally a fork from Kong's Unirest, NiduxRest has been completely rewritten from the ground up in v3.0 to embrace strict typing, isolated instances, and a beautiful fluent interface.

> **ATTENTION: BREAKING CHANGES (v3.0.0)**Version 3.0 is a complete architectural overhaul.
>
> - **New Namespace:** The namespace has been upgraded from `Niduxrest` to `Nidux\Rest` to comply with modern PSR-4 standards.
> - **No More Global State:** All static methods for requests (`Request::post()`, `Request::setJsonOpts()`, etc.) have been removed. The client now uses a strictly fluent, instance-based approach.
> - **Response Handling:** Responses are now predictable DTOs. Direct property access (e.g., `$response->code`) is removed in favor of strict getters.
> - **Deprecation removal:** All previous methods marked as deprecated have been removed.

If your project still relies on the classic static calls, please lock your `composer.json` to `"nidux/niduxrest-php": "^2.0"`, then perform a refactoring on non-production environments.

---

The Fluent Advantage: v3 vs v2
------------------------------

[](#the-fluent-advantage-v3-vs-v2)

Why the rewrite? In enterprise SaaS environments, relying on static global states (like setting global timeouts or headers) leads to unpredictable bugs when multiple API calls are made in the same lifecycle. Here on Nidux, we've encountered many of these bugs, leading to critical and weird issues in production. We did solve this problem by working around over version 2, but it was not a realistic solution for us. NiduxRest was needing a complete rewrite.

v3 introduces isolated instances with a fluent builder pattern.

**The Old Way (v2.0):** Positional arguments, easy to forget the order, relies on global state affecting all future requests in the same script.

```
// Setting global state (Dangerous in large apps)
\Niduxrest\Request::setTimeout(10);
$response = \Niduxrest\Request::post('https://api.example.com', ['Accept' => 'application/json'], $body);
```

**The New Way (v3.0.0):** Expressive, isolated, and IDE-friendly.

```
use Nidux\Rest\Request;

$response = Request::new()
    ->post('https://api.example.com')
    ->withHeader('Accept', 'application/json')
    ->withBearerToken('super-secret-token')
    ->timeout(10)
    ->withBody(['name' => 'John Doe'])
    ->send();
```

Requirements
------------

[](#requirements)

- [cURL](http://php.net/manual/en/book.curl.php)
- PHP 8.3+

Documentation
=============

[](#documentation)

Since this is a complete rewrite, the documentation is now focused on the new fluent interface. So if you need to refer to the old documentation, please refer to the [v2.0.1](https://github.com/Nidux/NiduxRest/tree/v2.0.1) tag.

Installation
------------

[](#installation)

### Using [Composer](https://getcomposer.org)

[](#using-composer)

To install NiduxRest with Composer, just add the following to your `composer.json` file:

```
{
  "require": {
    "nidux/niduxrest-php": "^3.0"
  }
}
```

or by running the following command:

```
composer require nidux/niduxrest-php
```

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

[](#basic-usage)

### Making Requests

[](#making-requests)

You can start a request using the `new()` static constructor and chain your configurations. You can use a very specific fluent approach or use some of the available helpers:

```
use Nidux\Rest\Request;
use Nidux\Rest\Enum\Method;

// GET Request with Query Parameters
$response = Request::new()
    ->to('https://postman-echo.com/get')
    ->withQuery(['search' => 'laptop', 'limit' => 10])
    ->send();

// POST Request (JSON by default)
$response = Request::new()
    ->to('https://postman-echo.com/post')
    ->withMethod(Method::POST)
    ->withBody(['sku' => '12345', 'price' => 99.99])
    ->send();

// GET Request with Query Parameters (with Helper)
$response = Request::new()
    ->get('https://postman-echo.com/get')
    ->withQuery(['search' => 'laptop', 'limit' => 10])
    ->send();

// POST Request (JSON by default) (with Helper)
$response = Request::new()
    ->post('https://postman-echo.com/post')
    ->withBody(['sku' => '12345', 'price' => 99.99])
    ->send();
```

*Available HTTP method helpers:* `->get()`, `->post()`, `->put()`, `->patch()`, `->delete()`, `->head()`, `->options()`, `->trace()`.

### Request Bodies

[](#request-bodies)

The `withBody()` method takes two arguments: the data array/object, and a boolean `$asJson` (default `true`).

```
// Send as application/json (Default)
->withBody(['name' => 'John']);

// Send as application/x-www-form-urlencoded
->withBody(['name' => 'John'], false);
```

### Multipart &amp; File Uploads

[](#multipart--file-uploads)

For `multipart/form-data` and file uploads, use the `withMultipartBody()` helper alongside the `Body::prepareFile()`utility:

```
use Nidux\Rest\Request;
use Nidux\Rest\Request\Body;

$response = Request::new()
    ->post('https://api.example.com/upload')
    ->withMultipartBody([
        'username' => 'ahmad',
        'avatar' => Body::prepareFile('/path/to/avatar.jpg', 'image/jpeg')
    ])
    ->send();
```

---

### The Response Object

[](#the-response-object)

NiduxRest v3 respects that different developers prefer different data structures. The Response object parses JSON automatically and allows you to retrieve data in three different ways:

```
$response = Request::new()->get('https://api.example.com/users/1')->send();

// 1. The Standard Object (stdClass)
$user = $response->getBody();
echo $user->name;

// 2. The Associative Array
$userArray = $response->getArray();
echo $userArray['name'];

// 3. The Raw String (Great for XML, CSV, or custom parsing)
$raw = $response->getRawBody();
```

### Status Helpers (Brand New!!)

[](#status-helpers-brand-new)

```
if ($response->isSuccessful()) { // Validates HTTP Codes from 200-299
    // Do something
}

if ($response->isClientError()) { // Validates HTTP Codes from 400-499
    echo "Check your payload!";
}

if ($response->isServerError()) { // Validates HTTP Codes from 500+
    echo "The external API is down.";
}

// Or get the exact code/headers
$response->getCode();    // e.g., 200
$response->getHeaders(); // Returns array of headers
```

---

### Advanced Configuration

[](#advanced-configuration)

Because the client is fluent, all configurations are isolated strictly to the instance being executed.

#### Authentication

[](#authentication)

```
// Bearer Token
Request::new()->withBearerToken('your-jwt-token')->...

// Basic Auth
Request::new()->withBasicAuth('username', 'password')->...
```

#### Proxies and Cookies

[](#proxies-and-cookies)

```
// Route traffic through a proxy
Request::new()
    ->withProxy('10.10.10.1', 8080)
    ->withProxyAuth('user', 'pass')
    ->...

// Read/Store cookies across requests (Session persistence)
Request::new()->withCookieFile('/path/to/cookie.txt')->...

// Send a manual cookie string
Request::new()->withCookie('fruit=apple; session=123')->...
```

#### Custom cURL Options (The Escape Hatch)

[](#custom-curl-options-the-escape-hatch)

If you need to define specific cURL behaviors that don't have a dedicated helper, you can inject native `CURLOPT_*`constants directly into the fluent chain:

```
Request::new()
    ->get('https://api.example.com')
    ->withCurlOption(CURLOPT_ENCODING, 'gzip')
    ->withCurlOption(CURLOPT_TCP_KEEPALIVE, 1)
    ->send();
```

##### Security (SSL) and Hostname Verification

[](#security-ssl-and-hostname-verification)

SSL verification is **enabled by default**. If you need to hit a local testing server with self-signed certificates:

```
Request::new()
    ->get('https://local.dev.nidux.com')
    ->setPeerVerification(false)
    ->setHostVerification(false)
    ->send();
```

Contributing &amp; Support
--------------------------

[](#contributing--support)

NiduxRest is still evolving driven by the needs of the whole Nidux ecosystem, but it is proudly open-sourced to give back to the PHP community. We are absolutely open to improvements, bug fixes, and new ideas!

If you want to contribute to this project:

- **Found a bug?** Please open an [Issue](https://github.com/nidux/niduxrest/issues) on GitHub with a clear description of the problem and, if possible, the steps to reproduce it.
- **Have a feature request or improvement?** Feel free to open an Issue to discuss it.
- **Want to write some code?** We welcome Pull Requests! Just make sure to run the PHPUnit test suite before submitting your PR to ensure everything stays green.

Let's build a better, faster HTTP client together.

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance95

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity72

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 ~222 days

Recently: every ~243 days

Total

9

Last Release

24d ago

Major Versions

v1.0.5 → v2.0.02023-10-10

v2.0.1 → v3.0.02026-04-07

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v2.0.0PHP &gt;=8.1

v3.0.0PHP &gt;=8.3

### Community

Maintainers

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

---

Top Contributors

[![cumanzorx07](https://avatars.githubusercontent.com/u/5851958?v=4)](https://github.com/cumanzorx07 "cumanzorx07 (2 commits)")

---

Tags

php8httpapiclientrestcurlfluentNidux

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nidux-niduxrest-php/health.svg)

```
[![Health](https://phpackages.com/badges/nidux-niduxrest-php/health.svg)](https://phpackages.com/packages/nidux-niduxrest-php)
```

###  Alternatives

[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.7M275](/packages/nategood-httpful)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

12262.2k1](/packages/e-moe-guzzle6-bundle)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4640.8k](/packages/ismaeltoe-osms)[openapi/openapi-sdk

Minimal and agnostic PHP SDK for Openapi® (https://openapi.com)

171.4k1](/packages/openapi-openapi-sdk)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2426.0k1](/packages/jsor-hal-client)

PHPackages © 2026

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