RestClient.Net

The safest way to make REST calls in C#. Built with functional programming, compile-time exhaustiveness, and modern .NET patterns.

Result Types

Returns Result<TSuccess, HttpError<TError>> with closed hierarchy types for compile-time safety. No more exception handling guesswork.

Zero Exceptions

No exception throwing for predictable error handling. Every possible outcome is represented in the type system.

Exhaustiveness Checking

Uses the Exhaustion analyzer for compile-time completeness guarantees. If you don't handle all cases, it won't compile.

HttpClient Extensions

Works with IHttpClientFactory.CreateClient() for proper pooled connections and DNS behavior handling.

OpenAPI Generator

Generate type-safe C# clients from OpenAPI 3.x specs. Automatic model generation and result type aliases.

MCP Server Generator

Generate Model Context Protocol servers for Claude Code from OpenAPI specs. AI-ready API integration.

Quick Install

dotnet add package RestClient.Net

Basic Usage

using RestClient.Net;

// Make a GET request
var result = await httpClient
    .GetAsync(
        url: "https://api.example.com/posts/1".ToAbsoluteUrl(),
        deserializeSuccess: DeserializePost,
        deserializeError: DeserializeError
    );

// Pattern match on the result - MUST handle all cases
var output = result switch
{
    OkPost(var post) => $"Success: {post.Title}",
    ErrorPost(ResponseErrorPost(var err, var status, _)) => $"Error {status}",
    ErrorPost(ExceptionErrorPost(var ex)) => $"Exception: {ex.Message}",
};

Why Discriminated Unions?

C# doesn't officially support discriminated unions yet, but RestClient.Net brings this powerful pattern to your code today. With the Exhaustion analyzer, missing a case means your code won't compile.

Without Exhaustion

// DANGEROUS - compiles but may throw
var output = result switch
{
    OkPost(var post) => "Success",
    ErrorPost(ResponseErrorPost(...)) => "Error",
    // Missing ExceptionErrorPost!
    // Runtime crash waiting to happen
};

With Exhaustion

// SAFE - compiler error!
// error EXHAUSTION001: Switch not exhaustive
// Missing: ExceptionErrorPost
// Build fails until you handle all cases

Ready to Get Started?