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

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

brzuchal/rest-client
====================

A new synchronous HTTP REST client offering a fluent API with the infrastructure of Symfony HttpClient

1.0.x-dev(1y ago)0565MITPHP

Since Mar 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/brzuchal/rest-client)[ Packagist](https://packagist.org/packages/brzuchal/rest-client)[ RSS](/packages/brzuchal-rest-client/feed)WikiDiscussions 1.0 Synced 1mo ago

READMEChangelogDependencies (14)Versions (1)Used By (0)

RestClient
==========

[](#restclient)

The RestClient package is a PHP library that simplifies working with RESTful APIs. It provides an easy way to create and configure HTTP requests, handle responses, and convert JSON data into PHP objects. This documentation will guide you through the main features and usage of the RestClient package.

Whether you're building web services or powerful API clients in your applications, the RestClient package streamlines the process of interacting with RESTful APIs in PHP. It allows you to focus on your application's functionality rather than the intricacies of making HTTP requests and processing responses.

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

[](#installation)

You can install the RestClient package via Composer:

```
composer require brzuchal/rest-client
```

Documentation
-------------

[](#documentation)

- [Basic usage](doc/basic.md)
- [Builder](doc/builder.md)
- [Entity Classes](doc/entity.md)
- [Custom Handling](doc/exchange.md)
- [Integrating with Symfony](doc/symfony.md)
- [Integrating with Laravel](doc/laravel.md)
- [Service Factory (Experimental)](doc/service-factory.md)

Getting Started
---------------

[](#getting-started)

To get started with the RestClient package, create a `RestClient` instance. You can use the `RestClient::create` method to do this:

```
use Brzuchal\RestClient\RestClient;

$client = RestClient::create('https://api.example.com/');
```

Now you have a `RestClient` instance ready to make HTTP requests.

Making Requests
---------------

[](#making-requests)

The RestClient package allows you to create various types of HTTP requests, such as GET, POST, PUT, DELETE, etc. You can use the RestClient instance to create request objects for these methods.

```
$response = $client->get('/todos/1')
    ->retrieve();
$data = $response->toArray();
$todo = $response->toEntity(Todo::class);
```

Error Handling
--------------

[](#error-handling)

```
$response = $client->get('/todos/1')
    ->retrieve();

$response->onStatus(404, function ($response) {
    throw new NotFoundException('Resource not found');
});

$response->onStatus(500, function ($response) {
    throw new ServerErrorException('Server error');
});
```

Symfony Framework
-----------------

[](#symfony-framework)

### Configuration

[](#configuration)

To use the RestClient package in a Symfony application, follow these steps:

1. Register the bundle in your Symfony application by adding the `RestClientBundle` to the `config/bundles.php` file:

    ```
    // config/bundles.php

    return [
        // ...
        Brzuchal\RestClient\RestClientBundle::class => ['all' => true],
    ];
    ```
2. By default, the RestClientBundle uses Symfony configuration to define REST client services. Create a configuration file (e.g., `rest_client.yaml`) in the `config/packages` directory of your Symfony project. Here's an example configuration:

    ```
    # config/packages/rest_client.yaml

    rest_client:
        clients:
            my_rest_client:
                base_uri: 'https://api.example.com/'
    ```

    In this configuration, we define a `my_rest_client` service with a base URI of `https://api.example.com/`. You can add more client configurations as needed.

### Example Symfony Controller

[](#example-symfony-controller)

Here's an example Symfony controller that uses the RestClient package to make API requests:

```
use Brzuchal\RestClient\RestClient;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class TodoController extends AbstractController
{
    public function index(
        #[Autowire(service: 'rest_client.default')]
        RestClientInterface $client,
    ): JsonResponse {
        return $this->json($client->get('/todos')->toArray());
    }
}
```

Laravel Framework
-----------------

[](#laravel-framework)

### Configuration

[](#configuration-1)

To use the RestClient package in a Laravel application, follow these steps:

1. Create a configuration file for the RestClient package using the following Artisan command:

    ```
    php artisan vendor:publish --tag=config
    ```

    This command will generate a `rest_client.php` configuration file in the `config` directory of your Laravel project.

    > **NOTE!**: Laravel 8 and later versions should automatically discover the package. For older Laravel versions, you may need to register the service provider manually.
2. The configuration for the RestClient package in Laravel is similar to Symfony. Here's an example configuration file (`config/rest_client.php`):

    ```
    return [
        'clients' => [
            'my_rest_client' => [
                'base_uri' => 'https://api.example.com/',
            ],
        ],
    ];
    ```

    In this configuration, we define a `my_rest_client` service with a base URI of `https://api.example.com/`. You can add more client configurations as needed.

### Example Laravel Controller

[](#example-laravel-controller)

Here's an example Laravel controller that uses the RestClient package to make API requests:

```
namespace App\Http\Controllers;

use Brzuchal\RestClient\RestClient;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

class TodoController extends Controller
{
    public function index(Request $request): JsonResponse
    {
        return response()->json(
            app('rest_client.default')->get('/todos')->toArray(),
        );
    }
}
```

License
-------

[](#license)

The RestClient package is open-source software licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance46

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

420d ago

### Community

Maintainers

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

---

Top Contributors

[![brzuchal](https://avatars.githubusercontent.com/u/3149753?v=4)](https://github.com/brzuchal "brzuchal (35 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[api-platform/symfony

Symfony API Platform integration

323.2M67](/packages/api-platform-symfony)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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