PHPackages                             jttp/jttp - 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. jttp/jttp

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

jttp/jttp
=========

Simple HTTP client on PHP.

10PHP

Since Mar 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Vasiliy-Bondarenko/jttp)[ Packagist](https://packagist.org/packages/jttp/jttp)[ RSS](/packages/jttp-jttp/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simple HTTP client
==================

[](#simple-http-client)

Status
------

[](#status)

Work in progress!

Motivation
----------

[](#motivation)

Create simple to use http client with minimum dependencies.

- Laravel style
- No dependencies
- Nice fluid interface
- JSON by default
- Code completion
- No magic
- Strict types where possible
- PHP 7.0
- Fully tested
- Easily extendable
- Throw exception on any error (non-2xx status, too many redirects, json\_decode error, etc)

Simple example
--------------

[](#simple-example)

```
require_once "vendor/autoload.php";

use Jttp\Jttp;
use Jttp\JttpException;

try {
    $response = (new Jttp)
        ->url("https://httpbin.org/get")
        ->get();

    echo "Status:   " . $response->status() . "\n\n";
    echo "Headers:  " . var_export($response->headers(), true) . "\n\n";
    echo "Body:     " . $response->body() . "\n\n";
    echo "Json:     " . var_export($response->json(), true) . "\n\n";
} catch (JttpException $e) {
    // it will catch all errors here including non 2xx response codes and json_decode errors
    echo "Error: {$e->getMessage()}\n";
}
```

Other fluid methods
-------------------

[](#other-fluid-methods)

```
->maxRedirects(5)               // follow maximum 5 redirects
->doNotFollowRedirects()

->asMultipart()                 // send request as multipart/form-data

->logToStderr()                 // enables logging debug information to stderr
->logToFile($filename = "")     // log to file

->retries(1)                    // retry request on network errors, remote server errors, etc
->pauseBetweenRetriesMs(1000)   // in milliseconds
```

All [http verbs](https://www.restapitutorial.com/lessons/httpmethods.html)
--------------------------------------------------------------------------

[](#all-http-verbs)

```
->get()
->post($data = null)
->put($data = null)
->patch($data = null)
->delete($data = null)
```

More complex example
--------------------

[](#more-complex-example)

If you are making a few request or just want to have client with the same setting - you can prepare client and use it many times like this:

```
// prepare http client
$client = (new Jttp)
    ->retries(2)
    ->redirects(5)
    ->logToFile("log.txt")
    ->pauseBetweenRetriesMs(1000);

try {
    // use it for first request
    echo "Get request: \n";
    $response = $client->url("https://httpbin.org/get")
                       ->get();
    var_dump($response->json());

    // use for second request to other url
    echo "Patch request: \n";
    $response = $client->url("https://httpbin.org/patch")
                       ->patch(["Key" => "value"]);
    var_dump($response->json());

} catch (JttpException $e) {
    // it will catch all errors here including non 2xx response codes and json_decode errors, too many redirects, etc
    echo "Error: {$e->getMessage()}\n";
}
```

You can try to run [examples.php](./examples.php) and copy-paste from it.

Advanced features
-----------------

[](#advanced-features)

You will know when you need them :) Normally it will happen if need to customize functionality of internal classes or for tests.

### Different transports

[](#different-transports)

Default transport is Curl. But if you want to implement your own transport or extend functionality of this Curl transport - you are free to do it.

#### Extending

[](#extending)

```
// extend Curl
class CustomTransport extends Curl
{
    // extend however you want...
}

// and use
$response = (new Jttp)
    ->useTransport((new CustomTransport()))
    ->url("https://httpbin.org/get")
    ->get();
```

#### Fully custom transport

[](#fully-custom-transport)

```
class CustomTransport implements TransportInterface
{

    public function setResponseObject(Response $response)
    {
        // TODO: Implement setResponseObject() method.
    }

    /**
     * @param string $method
     * @param string $url
     * @param mixed $data
     * @param bool $verbose
     * @return Response
     * @throws TransportException
     */
    public function call(string $method, string $url, string $body_format, $data = null, bool $verbose = false, $log_handler = null): Response
    {
        // TODO: Implement call() method.
    }
}

// and use
$response = (new Jttp)
    ->useTransport((new CustomTransport()))
    ->url("https://httpbin.org/get")
    ->get();
```

Custom response objects
-----------------------

[](#custom-response-objects)

```
// extend original class
class CustomResponse extends Response
{
    public function customMethod()
    {
        return "ok";
    }
}

// and inject info Jttp to use
$response = (new Jttp)
    ->useResponseObject(new CustomResponse())
    ->url("https://httpbin.org/get")
    ->get();

// use you response
echo $response->customMethod();
```

Package inspired by
-------------------

[](#package-inspired-by)

[Zttp by Adam Wathan](https://github.com/kitetail/zttp)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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/cfb5c85fd27439fa08a4b6204fea4005b76533f4dbea2d4222a1d92e1907b3cf?d=identicon)[Vasiliy-Bondarenko](/maintainers/Vasiliy-Bondarenko)

### Embed Badge

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

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

###  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)
