RESTCLIENT.NET
Menu
EN
↗ GitHub

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.

Outcome

The functional programming library providing discriminated unions for error handling.

Code Generators

Tools for generating type-safe clients from API specifications.

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:

  1. No exceptions for expected errors - HTTP errors are returned as values, not thrown
  2. Complete error handling - Pattern matching ensures all cases are handled
  3. Type safety - Generic parameters provide compile-time type checking
  4. Composability - Results can be mapped, bound, and combined functionally