PHPackages                             technicalguru/rest-client - 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. technicalguru/rest-client

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

technicalguru/rest-client
=========================

A PHP library for accessing REST services

v1.0.1(4y ago)01.0k1[1 issues](https://github.com/technicalguru/php-rest-client/issues)1LGPL-3.0-or-laterPHPPHP &gt;=7.0.0

Since Nov 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/technicalguru/php-rest-client)[ Packagist](https://packagist.org/packages/technicalguru/rest-client)[ RSS](/packages/technicalguru-rest-client/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (1)

php-rest-client
===============

[](#php-rest-client)

A lightweight REST client based on php-curl.

License
=======

[](#license)

This project is licensed under [GNU LGPL 3.0](LICENSE.md).

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

[](#installation)

By Composer
-----------

[](#by-composer)

```
composer install technicalguru/rest-client

```

By Package Download
-------------------

[](#by-package-download)

You can download the source code packages from [GitHub Release Page](https://github.com/technicalguru/php-rest-client/releases)

How to use
==========

[](#how-to-use)

Creating a Request
------------------

[](#creating-a-request)

Depending on your intent, all you need is the URL and the body if required:

```
use TgRestClient\Request;

$request = Request::get('https://www.example.com/endpoint');
$request = Request::put('https://www.example.com/endpoint', $myObject);
$request = Request::post('https://www.example.com/endpoint', $myObject);
$request = Request::delete('https://www.example.com/endpoint/123');

```

Request provides a static method for each of the HTTP methods: HEAD, GET, POST, PUT, PATCH, OPTIONS, DELETE.

Setting Request Headers
-----------------------

[](#setting-request-headers)

Additional headers for the request can be set like this:

```
use TgRestClient\Headers;

// individual headers
$request
    ->setHeader(Headers::AUTHORIZATION, 'Bearer 1234567890')
    ->setHeader(Headers::COOKIE,        'XSESSION=qwefjnqlkiu117o11ndn1');

// set multiple headers with a (key => value) array
$request->addHeaders($headers);

```

The Request Body
----------------

[](#the-request-body)

By default, `Request` assumes your body needs to be of `application\json` type. As such, the implementation already knows how to build a JSON encoding and you can pass an object or array for your body. `Request` will automatically stringify. Same is valid for `application/x-www-form-urlencoded`content. However, you will need to set the `Content-Type` header accordingly:

```
use TgRestClient\Request;
use TgRestClient\Headers;

$parameters = array(
    'name1' => 'value1',
    'name2' => 'value2',
);
$request = Request::post($url, $parameters)
    ->setHeader(Headers::CONTENT_TYPE, Headers::TYPE_X_WWW_FORM_URLENCODED);

```

Executing
---------

[](#executing)

Once you configured your request, you can simply execute it:

```
$response = $request->execute();

```

The execute call takes an optional argument - the number of seconds until the call times out. The default timeout is 5 seconds. The method will return latest after this time and give you a `Response` object.

The Response
------------

[](#the-response)

The response object returns everything you need to know about the result of your call:

```
$httpCode    = $response->getHttpCode();
$bodyObject  = $response->getBody();
$rawBody     = $response->getRawBody();
$headerValue = $response->getHeader('Server');

```

The `getBody()` method returns objects when the server returned a JSON-encoded body. Otherwise, you will get the raw body by this method too.

Defining Default Request Headers
--------------------------------

[](#defining-default-request-headers)

It can be very exhausting to set the same request headers for each individual request over and over again. That's why you can define default headers:

```
use TgRestClient\Headers;

// Single header
Headers::setDefaultHeader('www.example.com', Headers::AUTHORIZATION, 'Bearer 1234567890');

// or multiple
Headers::addDefaultHeaders('www.example.com', $myDefaultHeaders);

```

The headers will be available for each request to [www.example.com](http://www.example.com). However, you can override headers for individual requests if required. Just set the header on the request object.

Executing Requests Simultaneously
---------------------------------

[](#executing-requests-simultaneously)

One strength of the library is the ability to perform multiple requests at the same time:

```
use TgRestClient\Client;
use TgRestClient\Request;

// Build your request objects
$request1  = Request::get($url1);
$request2  = Request::get($url2);
...

// Create the client
$client = new Client();

// Add the requests to the client and get the Response objects
$response1 = $client->addCall($request1);
$response2 = $client->addCall($request2);
...

// Now execute all together
$responses = $client->run();

```

Please notice that the `Response` objects cannot be used before you called the `run()` method on the client.

The `run()` method again can take a timeout in seconds (which defaults to 5). It also returns an array of the `Response`objects in the order of how you added them to the client. That means, the first response belongs to the very first request you added, the seconds response to the second request you added, and so on.

You can also ask the `Response` object which `Request` it was executing:

```
$request1 = $responses[0]->getRequest();
$request2 = $responses[1]->getRequest();

```

Developer Remark
================

[](#developer-remark)

The PHP Unit test will require a [gorest.co.in](http://gorest.co.in) API token. Most tests will not be executed without this token stored in environment variable `GOREST_TOKEN`.

Contribution
============

[](#contribution)

Report a bug, request an enhancement or pull request at the [GitHub Issue Tracker](https://github.com/technicalguru/php-rest-client/issues).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

Total

2

Last Release

1794d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6360165?v=4)[Ralph Schuster](/maintainers/technicalguru)[@technicalguru](https://github.com/technicalguru)

---

Top Contributors

[![technicalguru](https://avatars.githubusercontent.com/u/6360165?v=4)](https://github.com/technicalguru "technicalguru (16 commits)")

---

Tags

jsonjson-datarest-apirest-clientrestapijsonrestrest-client

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jacwright/restserver

php rest server for very light-weight REST APIs

51070.0k3](/packages/jacwright-restserver)[givebutter/laravel-keyable

Add API keys to your Laravel models

187144.5k2](/packages/givebutter-laravel-keyable)

PHPackages © 2026

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