RESTCLIENT.NET / DOCUMENTATION
API Reference
Complete reference documentation for RestClient.Net and the Outcome library.
Core Packages
RestClient.Net
The main library providing type-safe HTTP operations with discriminated union return types.
- HttpClient Extensions - Extension methods for
HttpClient - IHttpClientFactory Extensions - Extension methods for
IHttpClientFactory - Delegates - Function delegates for serialization/deserialization
- Utilities - Helper classes like
ProgressReportingHttpContent
Outcome
The functional programming library providing discriminated unions for error handling.
- Result Type - The core
Result<TSuccess, TFailure>type - HttpError Type - HTTP-specific error representation
- Result Extensions - Extension methods for
Result - Unit Type - The void equivalent for functional programming
Code Generators
Tools for generating type-safe clients from API specifications.
- OpenAPI Generator - Generate C# clients from OpenAPI/Swagger specs
- MCP Generator - Generate Model Context Protocol servers from OpenAPI specs
Quick Start
using RestClient.Net;
using Outcome;
// Make a type-safe GET request
var result = await httpClient.GetAsync<User, ApiError>(
url: "https://api.example.com/users/1".ToAbsoluteUrl(),
deserializeSuccess: DeserializeJson<User>,
deserializeError: DeserializeJson<ApiError>
);
// Handle the result with pattern matching
var message = result switch
{
Result<User, HttpError<ApiError>>.Ok<User, HttpError<ApiError>>(var user)
=> $"Found user: {user.Name}",
Result<User, HttpError<ApiError>>.Error<User, HttpError<ApiError>>(var error)
=> error switch
{
HttpError<ApiError>.ErrorResponseError(var body, var status, _)
=> $"API Error {status}: {body.Message}",
HttpError<ApiError>.ExceptionError(var ex)
=> $"Exception: {ex.Message}",
_ => "Unknown error"
},
_ => "Unexpected"
};
Design Philosophy
RestClient.Net follows Railway Oriented Programming principles:
- No exceptions for expected errors - HTTP errors are returned as values, not thrown
- Complete error handling - Pattern matching ensures all cases are handled
- Type safety - Generic parameters provide compile-time type checking
- Composability - Results can be mapped, bound, and combined functionally