# Configure Resilient .NET HTTP Clients

Poor HTTP client lifetimes and retry settings can cause connection failures or repeated operations. This skill guides .NET client registration, resilience configuration, request handlers, and testing.

## Install

```bash
npx skillstore add codewithmukesh/httpclient-factory
```

## Metadata

- Status: approved
- Slug: codewithmukesh-httpclient-factory
- Skillstore revision: r1
- Version status: missing
- Tree hash: ed2db9fe2f2ea78fdffe5b2f4b24836d142983d9ccb823b6f9ebe3544556a33e
- Author: codewithmukesh
- GitHub username: codewithmukesh
- License: MIT
- Repository: https://github.com/codewithmukesh/dotnet-claude-kit/tree/23300897f4d1a276bc475e373ecfe886e43dd7c5/skills/httpclient-factory
- Ref: 7f45681b0327e778bad91dabd0ddd268beec2a19
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, network
- Quality score: 70
- Public page: https://skillstore.pages.dev/skills/codewithmukesh-httpclient-factory
- Manifest: https://skillstore.pages.dev/api/skills/codewithmukesh-httpclient-factory/manifest

## Capabilities

- Provides named and keyed HTTP client registration examples for .NET 10.
- Explains standard resilience strategies and demonstrates retry and timeout customization.
- Demonstrates bearer-token injection and correlation-header propagation through DelegatingHandlers.
- Shows connection lifetime, idle timeout, decompression, and connection-limit configuration.
- Provides an in-memory HttpMessageHandler example for isolated client tests.
- Identifies common lifetime, shared-header, cancellation, and resilience-handler mistakes.

## Use Cases

- Integrate an External API: Choose named or keyed clients, configure headers, and add suitable resilience policies for an ASP.NET Core integration.
- Review HTTP Reliability: Review connection lifetimes, timeout settings, unsafe retries, shared headers, and handler composition during a service reliability assessment.
- Isolate Client Tests: Use an in-memory HttpMessageHandler to test service behavior without contacting an external API.

## Prompt Templates

### Register a Named Client

```
Show a named IHttpClientFactory client for GitHub repository reads in .NET 10. Include request headers, cancellation, and required packages.
```

### Use a Keyed Client

```
Configure a keyed HTTP client for [API name] in an ASP.NET Core endpoint. Explain its lifetime and propagate cancellation tokens.
```

### Compose Handlers and Tests

```
Add bearer-token and correlation-ID handlers to [client name]. Use per-request headers and provide isolated tests with a custom HttpMessageHandler.
```

### Audit Payment Resilience

```
Review [payment client] for duplicate-charge risks. Assess retries, idempotency, timeouts, lifetimes, and handler stacking. Propose fixes and failure tests.
```

## Limitations

- Contains guidance and C\# snippets, not an executable library or an automated test suite.
- Examples require project-specific types, service registrations, and compatible .NET packages.
- Mentions Refit and hedging in a decision guide without complete implementation examples.
- The payment example requires retry safeguards or provider-supported idempotency before production use.

## Best Practices

- Use factory-managed clients and select dependency-injection lifetimes that preserve connection management.
- Review retry safety before enabling resilience for payments or other state-changing requests.
- Pass cancellation tokens, set authorization per request, and test clients with controlled handlers.

## Anti Patterns

- Creating and disposing a new HttpClient for every production request.
- Retrying non-idempotent operations without explicit safeguards against duplicate effects.
- Stacking standard retry and hedging handlers without a deliberate pipeline design.

## Security Audit

- Audited at: 2026-10-31T14:11:49.044\+00:00
- Summary: All 44 static findings are false positives: 39 match Markdown backticks, and five match illustrative HTTPS addresses. The payment example enables default retries without disabling unsafe methods, creating a duplicate-charge risk. No evidence found of prompt injection, command execution, or intentional data exfiltration.

## Stats

- Views: 0
- Downloads: 0
- Favorites: 0
- Popularity score: 0
