Tech Verse Logo
Enable dark mode
Laravel 12.44: Adds HTTP Client afterResponse() Callbacks

Laravel 12.44: Adds HTTP Client afterResponse() Callbacks

Tech Verse Daily

Tech Verse Daily

4 min read

The Laravel ecosystem continues to evolve with thoughtful improvements that focus on developer experience, clarity, and real-world use cases. The Laravel 12.44 release is no exception, bringing several notable enhancements that make everyday development cleaner and more expressive.

In this release, the Laravel team introduced:

  • 🔁 HTTP client callbacks that run after the response is built

  • 🧪 New TestResponse header assertion methods

  • 📅 Additional fluent date validation helpers

  • ✨ And other small but meaningful refinements

Let’s take a closer look at what’s new and how you can use these features in your Laravel applications.

Run Callbacks After Building an HTTP Response

One of the standout features in Laravel 12.44 is the ability to define callbacks that run after the HTTP response has been received and built.

This enhancement was contributed by Luke Kuzmish and introduces a new afterResponse() method on Laravel’s HTTP client.

Why This Matters

Before this release, response handling logic was usually done inline after making the request:

  • Logging headers

  • Triggering events

  • Transforming responses

  • Detecting API deprecations

Now, you can attach this logic directly to the HTTP client, keeping your code more declarative and reusable.

Basic Example: Using afterResponse()

return Http::acceptJson()
    ->withHeader('X-Shopify-Access-Token', $shopCreds->token)
    ->baseUrl("https://{$shopCreds->shop_domain}.myshopify.com/admin/api/2025-10/")
    ->afterResponse(function (Response $response) {
        logger()->info('Response received', [
            'status' => $response->status(),
        ]);
    })
    ->get('products.json');

The callback runs after the response is fully constructed, giving you access to headers, status codes, and body content.

Real-World Use Case: Shopify API Deprecation Monitoring

A powerful use case is monitoring API deprecation warnings returned in headers.

return Http::acceptJson()
    ->withHeader('X-Shopify-Access-Token', $shopCreds->token)
    ->baseUrl("https://{$shopCreds->shop_domain}.myshopify.com/admin/api/2025-10/")
    ->afterResponse(function (Response $response) use ($shopCreds) {
        $header = $response->header('X-Shopify-API-Deprecated-Reason');

        if ($header) {
            event(new ShopifyDeprecationNotice(
                $shopCreds->shop,
                $header
            ));
        }
    })
    ->get('orders.json');

This keeps deprecation handling out of your business logic and close to the HTTP layer where it belongs.

Mapping Responses to Custom Classes

Another powerful feature: mutating the response by returning a new object.

->afterResponse(
    fn (Response $response) =>
        new ShopifyResponse($response->toPsrResponse())
)

This allows you to:

  • Wrap responses in custom DTOs

  • Normalize third-party API responses

  • Maintain a clean domain layer

New TestResponse Header Assertion Method

Testing HTTP responses just got more expressive.

Laravel 12.44 introduces a new assertion method for response headers, making your tests more readable and intention-revealing.

Example

$response->assertHeader('X-RateLimit-Remaining');

Or with a value check:

$response->assertHeader('Content-Type', 'application/json');

Why It’s Useful

  • Clearer intent in tests

  • Less reliance on manual header inspection

  • Better failure messages when assertions fail

This is especially useful when testing APIs, rate-limiting logic, or third-party integrations.

Additional Fluent Date Validation Methods

Laravel’s validation system continues to become more expressive with additional fluent date validation helpers.

Instead of writing complex rules manually, you can now express date constraints more clearly.

Example

use Illuminate\Validation\Rules\Date;

$request->validate([
    'start_date' => [
        'required',
        Date::parseable()->beforeOrEqual('today'),
    ],
]);

Benefits

  • Improved readability

  • Reduced validation bugs

  • More intention-revealing rules

This is particularly helpful when working with:

  • Booking systems

  • Subscription periods

  • Reports and analytics

  • Event scheduling

Small Improvements That Add Up

Like many Laravel releases, version 12.44 also includes several under-the-hood refinements and DX improvements that may not make headlines but significantly improve day-to-day development.

These incremental updates reinforce Laravel’s philosophy:

Make the common case simple, and the complex case possible.

Final Thoughts

Laravel 12.44 is a strong example of how small, focused features can have a big impact:

  • afterResponse() brings cleaner HTTP client architecture

  • Improved test assertions lead to better test readability

  • Fluent date validation reduces cognitive overhead

If you rely heavily on third-party APIs, write a lot of tests, or value expressive validation rules, this release is well worth upgrading.

As always, kudos to the Laravel core team and community contributors for continuing to push the framework forward.

    Latest Posts

    View All

    Laravel 12.44: Adds HTTP Client afterResponse() Callbacks

    Laravel 12.44: Adds HTTP Client afterResponse() Callbacks

    Laravel Artifact: Manage Your Media Easily

    Laravel Artifact: Manage Your Media Easily

    Handling Large File Uploads in Laravel: A Guide to Chunking & Resuming

    Handling Large File Uploads in Laravel: A Guide to Chunking & Resuming

    Next-Gen Laravel Deployment: FrankenPHP + Octane on Ubuntu VPS

    Next-Gen Laravel Deployment: FrankenPHP + Octane on Ubuntu VPS

    Speed Up Your Laravel App: Mastering Concurrent API Requests with Http::pool and Batch

    Speed Up Your Laravel App: Mastering Concurrent API Requests with Http::pool and Batch

    Beyond the Basics: Building Production-Ready APIs with Laravel

    Beyond the Basics: Building Production-Ready APIs with Laravel

    PHP 8.6: Expected Release Window and RFCs to Watch

    PHP 8.6: Expected Release Window and RFCs to Watch

    Downloading Files from External URLs in Laravel

    Downloading Files from External URLs in Laravel

    Pause and Resume Laravel Queue Workers on Demand

    Pause and Resume Laravel Queue Workers on Demand

    Resume Canvas - Open Source Resume Builder

    Resume Canvas - Open Source Resume Builder