> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# ResponseSnapshotCaptureHandler

> A [DelegatingHandler](https://learn.microsoft.com/dotnet/api/system.net.http.delegatinghandler) that captures HTTP responses and saves them as snapshot files.

## Definition

**Assembly:** CloudNimble.Breakdance.Assemblies.dll

**Namespace:** CloudNimble.Breakdance.Assemblies.Http

**Inheritance:** CloudNimble.Breakdance.Assemblies.Http.ResponseSnapshotHandlerBase

## Syntax

```csharp theme={"dark"}
CloudNimble.Breakdance.Assemblies.Http.ResponseSnapshotCaptureHandler
```

## Summary

A [DelegatingHandler](https://learn.microsoft.com/dotnet/api/system.net.http.delegatinghandler) that captures HTTP responses and saves them as snapshot files.

## Remarks

This handler passes requests through to the actual endpoint, then captures the response
and saves it as a snapshot file. This enables recording real API responses for later
replay during testing.

Use this handler during an initial recording phase to capture responses from third-party
APIs, then use [ResponseSnapshotReplayHandler](/breakdance/api-reference/CloudNimble/Breakdance/Assemblies/Http/ResponseSnapshotReplayHandler) to replay those responses
during test execution without hitting live endpoints.

## Examples

```csharp theme={"dark"}
// Create a handler that captures responses to snapshot files
var innerHandler = new HttpClientHandler();
var captureHandler = new ResponseSnapshotCaptureHandler("TestData/Snapshots")
{
    InnerHandler = innerHandler
};
var client = new HttpClient(captureHandler);

// Requests go to the real endpoint, responses are saved as snapshots
var response = await client.GetAsync("https://api.example.com/users");
```

## Constructors

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> .ctor

Creates a new [ResponseSnapshotCaptureHandler](/breakdance/api-reference/CloudNimble/Breakdance/Assemblies/Http/ResponseSnapshotCaptureHandler) that saves response snapshots to the specified path.

#### Syntax

```csharp theme={"dark"}
public ResponseSnapshotCaptureHandler(string responseSnapshotsPath)
```

#### Parameters

| Name                    | Type     | Description                                           |
| ----------------------- | -------- | ----------------------------------------------------- |
| `responseSnapshotsPath` | `string` | Root folder path for storing response snapshot files. |

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> .ctor <Badge color="gray">Inherited</Badge>

<Note>Inherited from `CloudNimble.Breakdance.Assemblies.Http.ResponseSnapshotHandlerBase`</Note>

Creates a new [ResponseSnapshotHandlerBase](/breakdance/api-reference/CloudNimble/Breakdance/Assemblies/Http/ResponseSnapshotHandlerBase) with the specified snapshot storage path.

#### Syntax

```csharp theme={"dark"}
public ResponseSnapshotHandlerBase(string responseSnapshotsPath)
```

#### Parameters

| Name                    | Type     | Description                                           |
| ----------------------- | -------- | ----------------------------------------------------- |
| `responseSnapshotsPath` | `string` | Root folder path for storing response snapshot files. |

#### Examples

```csharp theme={"dark"}
var handler = new ResponseSnapshotReplayHandler("TestData/Snapshots");
var client = new HttpClient(handler);
```

## Properties

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> ResponseSnapshotsPath <Badge color="gray">Inherited</Badge>

<Note>Inherited from `CloudNimble.Breakdance.Assemblies.Http.ResponseSnapshotHandlerBase`</Note>

Gets the root folder path where response snapshot files are stored.

#### Syntax

```csharp theme={"dark"}
public string ResponseSnapshotsPath { get; private set; }
```

#### Property Value

Type: `string`

## Methods

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> GetFileExtensionString <Badge color="gray">Inherited</Badge>

<Note>Inherited from `CloudNimble.Breakdance.Assemblies.Http.ResponseSnapshotHandlerBase`</Note>

Maps the MediaType header in the [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) to a known list of file extensions.

#### Syntax

```csharp theme={"dark"}
public static string GetFileExtensionString(System.Net.Http.HttpRequestMessage request)
```

#### Parameters

| Name      | Type                                 | Description             |
| --------- | ------------------------------------ | ----------------------- |
| `request` | `System.Net.Http.HttpRequestMessage` | The request to examine. |

#### Returns

Type: `string`
The file extension string for the request's Accept header.

#### Exceptions

| Exception               | Description                  |
| ----------------------- | ---------------------------- |
| `ArgumentNullException` | Thrown when request is null. |

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> GetPathInfo <Badge color="gray">Inherited</Badge>

<Note>Inherited from `CloudNimble.Breakdance.Assemblies.Http.ResponseSnapshotHandlerBase`</Note>

Parses the RequestUri in the [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) into a [Path](https://learn.microsoft.com/dotnet/api/system.io.path)-safe string
suitable for storing response snapshots on the file system.

#### Syntax

```csharp theme={"dark"}
internal static (string, string) GetPathInfo(System.Net.Http.HttpRequestMessage request, string responseSnapshotsPath)
```

#### Parameters

| Name                    | Type                                 | Description                                                                                                   |
| ----------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
| `request`               | `System.Net.Http.HttpRequestMessage` | The [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) to parse. |
| `responseSnapshotsPath` | `string`                             | Root folder for storing snapshot files.                                                                       |

#### Returns

Type: `(string, string)`
A tuple containing the directory path and file path components.

#### Exceptions

| Exception                   | Description                                                   |
| --------------------------- | ------------------------------------------------------------- |
| `ArgumentException`         | Thrown when the request has an invalid RequestUri.            |
| `InvalidOperationException` | Thrown when the URI cannot be converted to a valid file path. |

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> GetResponseMediaTypeString <Badge color="gray">Inherited</Badge>

<Note>Inherited from `CloudNimble.Breakdance.Assemblies.Http.ResponseSnapshotHandlerBase`</Note>

Maps the file extension in the specified path to a known list of media types.

#### Syntax

```csharp theme={"dark"}
public static string GetResponseMediaTypeString(string filePath)
```

#### Parameters

| Name       | Type     | Description               |
| ---------- | -------- | ------------------------- |
| `filePath` | `string` | The file path to examine. |

#### Returns

Type: `string`
The MIME type string for the file extension.
