> ## Documentation Index
> Fetch the complete documentation index at: https://docs.unleash-commerce.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Responses

> Replace and customize HTTP responses in Unleash Commerce Core

## Overview

Core controllers return response contracts that implement `Responsable`. You can replace any core response by binding its contract to your own class.

## Replace a core response

Create a custom response that implements the same contract:

```php theme={null}
namespace App\Http\Responses;

use Esign\UnleashCommerce\Core\Contracts\Http\Responses\ProductResponse as ProductResponseContract;
use Esign\UnleashCommerce\Core\Contracts\Models\Product as ProductContract;
use Inertia\Inertia;

class ProductResponse implements ProductResponseContract
{
    public function __construct(protected ProductContract $product) {}

    public function toResponse($request)
    {
        return Inertia::render('Products/Show', [
            'product' => $this->product,
            'extra' => 'Custom payload',
        ])->toResponse($request);
    }
}
```

## Bind the response contract

Bind the contract to your custom class in a service provider:

```php theme={null}
<?php

namespace App\Providers;

use App\Http\Responses\ProductResponse;
use Esign\UnleashCommerce\Core\Contracts\Http\Responses\ProductResponse as ProductResponseContract;
use Illuminate\Support\ServiceProvider;

class UnleashCommerceServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->registerResponses();
    }

    protected function registerResponses(): void
    {
        $this->app->bind(
            ProductResponseContract::class,
            ProductResponse::class
        );
    }
}
```

## Use responses in controllers

Return response contracts and resolve them from the container when you need constructor arguments:

```php theme={null}
namespace App\Http\Controllers;

use Esign\UnleashCommerce\Core\Contracts\Http\Responses\ProductResponse as ProductResponseContract;
use Esign\UnleashCommerce\Core\Contracts\Models\Product as ProductContract;
use Illuminate\Http\Request;

class ProductController
{
    public function show(ProductContract $product, Request $request): ProductResponseContract
    {
        return app(ProductResponseContract::class, [
            'product' => $product,
        ]);
    }
}
```

## Available response contracts

See the [Responses Reference](../reference/responses) for a complete list of available response contracts.
