Version

Welcome to Kampute.HttpClient

REST integrations need more than an HTTP call: requests carry authentication and context, responses need to become application models, and failures need a recovery policy. Kampute.HttpClient brings these concerns together around the native .NET HttpClient.

The library is useful when you want to write an API client around your application's own models and operations. You choose the endpoints, payloads, and recovery rules; HttpRestClient provides the request helpers and configuration behind them.

A Familiar HTTP Foundation

HttpRestClient wraps HttpClient, so your integration can use the .NET HTTP stack's message handlers, proxies, and timeouts. You can supply a client managed by your application or use the library's shared client, which reuses connections across wrappers.

This lets an API wrapper keep its own base address, headers, content formatters, and error handlers while sharing the underlying connection infrastructure. Application code can expose operations such as loading an account or updating a resource without repeating HTTP setup in each method.

Application Models and Content Formats

Use helpers such as GetAsync<T>() and PostAsJsonAsync<T>() to work with typed responses and request payloads. Registered content formatters read a response according to its Content-Type and the model you request. When you need the body directly, helpers also return strings, byte arrays, or streams.

XML support is included in the core package. JSON extensions let you choose System.Text.Json or Newtonsoft.Json, and custom formatters can support application-specific media types. A client can register more than one format when an API returns different kinds of content.

Formatters are explicit: a new client starts with none registered. Configure the formats your integration needs before requesting typed responses.

Request Configuration Where It Belongs

Set default headers for values shared by an API client's requests. Use a request scope when an operation needs a temporary tenant identifier, authorization header, or different accepted media type. Disposing the scope restores the prior configuration, so each operation does not need to undo its overrides manually.

Request properties carry context for message handlers and hooks. The BeforeSendingRequest and AfterReceivingResponse events let you enrich outgoing messages or inspect status and headers around the HTTP operation.

Recovery That Matches Your API

Choose a retry policy for transient connection failures, with delays and limits supplied by Kampute.Resilience. Retries are opt-in: the default connection policy does not retry.

HTTP error responses have a separate recovery path. Register error handlers to refresh authorization after a 401 response or schedule retries for selected status codes. Structured error bodies can be deserialized into your API's error model; an unrecovered error response raises HttpResponseException.

Get Started

For a JSON API, install the JSON extension for the serializer your application uses. For XML or raw response bodies, start with the core package. The getting-started guide walks through package selection, formatter registration, and a first typed request.