PHPackages                             dragon-code/laravel-http-macros - 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. dragon-code/laravel-http-macros

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

dragon-code/laravel-http-macros
===============================

Extending the functionality of the Laravel HTTP client

1.5.0(3mo ago)11218MITPHPPHP ^8.2CI passing

Since Aug 22Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/TheDragonCode/laravel-http-macros)[ Packagist](https://packagist.org/packages/dragon-code/laravel-http-macros)[ Fund](https://boosty.to/dragon-code)[ Fund](https://yoomoney.ru/to/410012608840929)[ RSS](/packages/dragon-code-laravel-http-macros/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (7)Dependencies (8)Versions (10)Used By (0)

HTTP Macros for Laravel
=======================

[](#http-macros-for-laravel)

  ![Laravel Http Macros](https://camo.githubusercontent.com/799292766418dac37213e94cfd44516021afb39d4c6c835eae8a77d20dfdb51e/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230487474702532304d6163726f732e706e673f7061747465726e3d746f706f677261706879267374796c653d7374796c655f3226666f6e7453697a653d3130307078266d643d312673686f7757617465726d61726b3d31267468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d647261676f6e2d636f64652532466c61726176656c2d687474702d6d6163726f73266465736372697074696f6e3d457874656e64696e672b7468652b66756e6374696f6e616c6974792b6f662b7468652b4c61726176656c2b485454502b636c69656e7426696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)[![Stable Version](https://camo.githubusercontent.com/6de3734507ea80f0c235550ac80dd2ee564571ae8dc42fa93ca3e671407ac48b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f546865447261676f6e436f64652f6c61726176656c2d687474702d6d6163726f733f6c6162656c3d7061636b6167697374267374796c653d666c61742d737175617265)](https://packagist.org/packages/dragon-code/laravel-http-macros)[![Total Downloads](https://camo.githubusercontent.com/93130a104fab08c1c2f0f6c5e160191fbb811518e461703c0c6ae3f207381656/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f647261676f6e2d636f64652f6c61726176656c2d687474702d6d6163726f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dragon-code/laravel-http-macros)[![Github Workflow Status](https://camo.githubusercontent.com/b8bc42a348eb44537790ccecd9c6e5f15d0c8bf3291026a52ce03b6153cabb8b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f546865447261676f6e436f64652f6c61726176656c2d687474702d6d6163726f732f706870756e69742e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/TheDragonCode/laravel-http-macros/actions)[![License](https://camo.githubusercontent.com/c77adaae852f2a157cfcc54142ed7829e87bc82e17773597b4e0e27048774d1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f647261676f6e2d636f64652f6c61726176656c2d687474702d6d6163726f732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

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

[](#installation)

To get the latest version of `HTTP Macros`, simply require the project using [Composer](https://getcomposer.org):

```
composer require dragon-code/laravel-http-macros
```

Configuration
-------------

[](#configuration)

If desired, you can publish the configuration file using the console command:

```
php artisan vendor:publish --provider="DragonCode\\LaravelHttpMacros\\ServiceProvider"
```

If your application already has a `config/http.php` file, then you can simply add a new `macros` key from the [configuration](config/http.php) file to it.

Here you can specify a list of your classes for registering macros. Macro classes must inherit from the abstract class `DragonCode\LaravelHttpMacros\Macros\Macro`.

You can also redefine macro names using an associative array. For example:

```
// Config
return [
    'macros' => [
        'request' => [
            WithLoggerMacro::class,
        ],
        'response' => [
            ToDataMacro::class,
        ],
    ],
];

// Macro
Http::withLogger('some')->get();
Http::withLogger('some')->get()->toData(...);
Http::get()->toData(...);
```

```
// Config
return [
    'macros' => [
        'request' => [
            'qwerty' => WithLoggerMacro::class,
        ],
        'response' => [
            'qwerty' => ToDataMacro::class,
        ],
    ],
];

// Macro
Http::qwerty('some')->get();
Http::qwerty('some')->get()->qwerty(...);
Http::qwerty('some')->get()->toData(...); // method not found

Http::get()->qwerty(...);
Http::get()->toData(...); // method not found
```

Usage
-----

[](#usage)

### Available Methods

[](#available-methods)

#### Request

[](#request)

- [withLogger](#withlogger)

#### Response

[](#response)

- [toData](#todata)
- [toDataCollection](#todatacollection)

### Method Listing

[](#method-listing)

#### withLogger()

[](#withlogger)

Adds the ability to log HTTP requests and responses.

```
use Illuminate\Support\Facades\Http;

Http::withLogger('some_channel')->get();
```

This method will log HTTP requests and responses.

It is also possible to use your own handler, message formatting and path to the log file. To do this, you need to specify the desired channel name from the log file and define the necessary parameters in it.

For example:

```
// config/logging.php
return [
    // ...

    'channels' => [
        'some' => [
            'driver' => 'single',
            'level' => env('LOG_LEVEL', 'debug'),
            'path' => storage_path('logs/some.log'),
            'handler' => \App\Logging\SomeHandlerStack::class,
            'formatter' => \App\Logging\MessageFormatter::class,
        ],
    ],
];

// Usage
return Http::withLogger('some')->...
```

#### toData()

[](#todata)

The class instance will be returned.

```
use Illuminate\Support\Facades\Http;

// Returns a SomeData object
return Http::get()->toData(SomeData::class);

// Will return a SomeData object generated from the JSON path
return Http::get()->toData(SomeData::class, 'data.item');

// Returns the result of the callback execution
return Http::get()->toData(
    fn (array $data) => new SomeData(
        $data['data']['item']['id'],
        $data['data']['item']['title']
    )
);

// Returns the result of the callback execution from a custom JSON path
return Http::get()->toData(
    fn (array $data) => new SomeData($data['id'], $data['title']),
    'data.item'
);
```

> Note
>
> If a `from` method exists in a class, then it will be called to construct the object.
>
> Compatible with [Spatie Laravel Data](https://spatie.be/docs/laravel-data).

```
class SomeData
{
    public function __construct(
        public int $id,
        public string $title
    ) {}

    public static function from(array $data): static
    {
        return new static(...$data);
    }
}

return Http::get()->toData(SomeData::class);
```

#### toDataCollection()

[](#todatacollection)

The `Illuminate\Support\Collection` object or an object inherited from it will be returned.

```
use Illuminate\Support\Facades\Http;

// Returns a collection of SomeData objects
return Http::get()->toDataCollection(SomeData::class);

// Returns a collection of SomeData objects formed from the JSON path
return Http::get()->toDataCollection(SomeData::class, 'data.item');

// Returns the result of the callback execution
return Http::get()->toDataCollection(
    fn (array $data) => collect([
        new SomeData(
            $data['data']['item']['id'],
            $data['data']['item']['title']
        ),
    ])
);

// Returns the result of the callback execution from a custom JSON path
return Http::get()->toDataCollection(
    fn (array $data) => collect([
        new SomeData(...$data),
    ]),
    'data.item'
);
```

> Note
>
> If a `collect` method exists in a class, then it will be called to construct the collection.
>
> Compatible with [Spatie Laravel Data](https://spatie.be/docs/laravel-data).

```
use Illuminate\Support\Collection;

class SomeData
{
    public function __construct(
        public int $id,
        public string $title
    ) {}

    public static function collect(array $items): Collection
    {
        return collect($items)->map(
            fn (array $item) => new static(...$item)
        );
    }
}

return Http::get()->toDataCollection(SomeData::class);
```

### Generate IDE Helper files

[](#generate-ide-helper-files)

You can generate helper files for the IDE using the console command:

```
php artisan http:macros-helper
```

This will help your IDE suggest methods.

[![IDE Helper](.github/images/ide-helper.png)](.github/images/ide-helper.png)

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE).

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance82

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.2% 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 ~82 days

Recently: every ~143 days

Total

8

Last Release

96d ago

### Community

Maintainers

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

---

Top Contributors

[![andrey-helldar](https://avatars.githubusercontent.com/u/10347617?v=4)](https://github.com/andrey-helldar "andrey-helldar (58 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

---

Tags

httphttp-clientlaravellaravel-frameworkmacroshttplaraveldragon codeandrey helldarmacroshelldar

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/dragon-code-laravel-http-macros/health.svg)

```
[![Health](https://phpackages.com/badges/dragon-code-laravel-http-macros/health.svg)](https://phpackages.com/packages/dragon-code-laravel-http-macros)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[dragon-code/pretty-routes

Pretty Routes for Laravel

10063.3k4](/packages/dragon-code-pretty-routes)[dragon-code/laravel-cache

An improved interface for working with cache

6845.6k10](/packages/dragon-code-laravel-cache)[onlime/laravel-http-client-global-logger

A global logger for the Laravel HTTP Client

2037.5k](/packages/onlime-laravel-http-client-global-logger)

PHPackages © 2026

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