RestClient.Net
7.1.0
See the version list below for details.
dotnet add package RestClient.Net --version 7.1.0
NuGet\Install-Package RestClient.Net -Version 7.1.0
<PackageReference Include="RestClient.Net" Version="7.1.0" />
<PackageVersion Include="RestClient.Net" Version="7.1.0" />
<PackageReference Include="RestClient.Net" />
paket add RestClient.Net --version 7.1.0
#r "nuget: RestClient.Net, 7.1.0"
#:package RestClient.Net@7.1.0
#addin nuget:?package=RestClient.Net&version=7.1.0
#tool nuget:?package=RestClient.Net&version=7.1.0
RestClient.Net
The safest way to make REST calls in C#
Built from the ground up with functional programming, type safety, and modern .NET patterns. Successor to the original RestClient.Net.
What Makes It Different
This library is uncompromising in its approach to type safety and functional design:
- HttpClient extensions - Works with HttpClient lifecycle management via
IHttpClientFactory.CreateClient() - Result types - Explicit error handling without exceptions
- Exhaustiveness checking - Compile-time guarantees via Exhaustion
- Functional composition - Delegate factories, pure functions, no OOP ceremony
Features
- Result Types - Returns
Result<TSuccess, HttpError<TError>>with closed hierarchy types for compile-time safety (Outcome package) - Zero Exceptions - No exception throwing for predictable error handling
- Progress Reporting - Built-in download/upload progress tracking
- Polly Integration - Support for convention-based retry policies and resilience patterns
- Async/Await Only - Modern async patterns throughout
- HttpClient Extensions - Works with
IHttpClientFactory.CreateClient()for proper pooled connections and DNS behavior handling - Exhaustiveness Checking - Uses Exhaustion for compile-time completeness guarantees (stopgap until C# adds discriminated unions)
The design focuses on discriminated unions for results, and adding the Exhaustion analyzer package gives you exhaustive pattern matching on type in C#. RestClient.Net is well ahead of the game. You can use discriminated unions with exhaustiveness checks in C# right now.
Installation
dotnet add package RestClient.Net
Usage
Basic GET Request
The simplest way to make a GET request to JSONPlaceholder:
using System.Net.Http.Json;
using RestClient.Net;
// Define a simple User model
public record User(int Id, string Name, string Email);
// Get HttpClient from IHttpClientFactory
var httpClient = httpClientFactory.CreateClient();
// Make a direct GET request
var result = await httpClient.GetAsync<User, string>(
url: "https://jsonplaceholder.typicode.com/users/1".ToAbsoluteUrl(),
deserializeSuccess: (response, ct) => response.Content.ReadFromJsonAsync<User>(ct),
deserializeError: (response, ct) => response.Content.ReadAsStringAsync(ct)
);
switch (result)
{
case OkUser(var user):
Console.WriteLine($"Success: {user.Name}");
break;
case ErrorUser(var error):
Console.WriteLine($"Failed: {error.StatusCode} - {error.Body}");
break;
}
Result Type and Type Aliases
C# doesn't officially support discriminated unions, but you can achieve closed type hierarchies with the sealed modifer. The Outcome package gives you a set of Result types designed for exhaustiveness checks. Until C# gains full discriminated union support, you need to add type aliases like this. If you use the generator, it will generate the type aliases for you.
// Type aliases for concise pattern matching
using OkUser = Result<User, HttpError<string>>.Ok<User, HttpError<string>>;
using ErrorUser = Result<User, HttpError<string>>.Error<User, HttpError<string>>;
OpenAPI Code Generation
Generate type-safe extension methods from OpenAPI specs:
using JSONPlaceholder.Generated;
// Get HttpClient from factory
var httpClient = factory.CreateClient();
// GET all todos
var todos = await httpClient.GetTodos(ct);
// GET todo by ID
var todo = await httpClient.GetTodoById(1, ct);
switch (todo)
{
case OkTodo(var success):
Console.WriteLine($"Todo: {success.Title}");
break;
case ErrorTodo(var error):
Console.WriteLine($"Error: {error.StatusCode} - {error.Body}");
break;
}
// POST - create a new todo
var newTodo = new TodoInput { Title = "New Task", UserId = 1, Completed = false };
var created = await httpClient.CreateTodo(newTodo, ct);
// PUT - update with path param and body
var updated = await httpClient.UpdateTodo((Params: 1, Body: newTodo), ct);
// DELETE - returns Unit
var deleted = await httpClient.DeleteTodo(1, ct);
dotnet add package RestClient.Net.OpenApiGenerator
Define your schema (OpenAPI 3.x):
openapi: 3.0.0
paths:
/users/{id}:
get:
operationId: getUserById
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/User'
/users:
post:
operationId: createUser
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'201':
content:
application/json:
schema:
$ref: '#/components/schemas/User'
The generator creates:
- Extension methods - Strongly-typed methods on
HttpClient - Model classes - DTOs from schema definitions
- Result type aliases - Convenient
OkUserandErrorUsertypes
Generated usage:
// Get HttpClient from factory
var httpClient = factory.CreateClient();
// GET with path parameter
var user = await httpClient.GetUserById("123", ct);
// POST with body
var created = await httpClient.CreateUser(newUser, ct);
// PUT with path param and body
var updated = await httpClient.UpdateUser((Params: "123", Body: user), ct);
// DELETE returns Unit
var deleted = await httpClient.DeleteUser("123", ct);
All generated methods:
- Create extension methods on
HttpClient(use withIHttpClientFactory.CreateClient()) - Return
Result<TSuccess, HttpError<TError>>for functional error handling - Bundle URL/body/headers into
HttpRequestPartsviabuildRequest - Support progress reporting through
ProgressReportingHttpContent
Progress Reporting
You can track upload progress with ProgressReportingHttpContent. This example writes to the console when there is a progress report.
var fileBytes = await File.ReadAllBytesAsync("document.pdf");
using var content = new ProgressReportingHttpContent(
fileBytes,
progress: (current, total) =>
Console.WriteLine($"Progress: {current}/{total} bytes ({current * 100 / total}%)")
);
var httpClient = httpClientFactory.CreateClient();
var result = await httpClient.PostAsync<UploadResponse, string>(
url: "https://api.example.com/upload".ToAbsoluteUrl(),
requestBody: content,
deserializeSuccess: (r, ct) => r.Content.ReadFromJsonAsync<UploadResponse>(ct),
deserializeError: (r, ct) => r.Content.ReadAsStringAsync(ct)
);
Upgrading from RestClient.Net 6.x
You can continue to use the V6 IClient interface with RestClient .Net 7. RestClient.Net 7 is a complete rewrite with a functional architecture. For existing v6 users, RestClient.Net.Original provides a polyfill that implements the v6 IClient interface using v7 under the hood.
Using the Polyfill
Install both packages:
dotnet add package RestClient.Net.Original
dotnet add package RestClient.Net.Abstractions --version 6.0.0
Use Client to maintain v6 compatibility while benefiting from v7's improvements:
using RestClient.Net;
var client = new Client(
httpClientFactory,
baseUrl: "https://api.example.com".ToAbsoluteUrl(),
defaultRequestHeaders: new HeadersCollection(),
throwExceptionOnFailure: true
);
// Continue using your existing v6 IClient extension methods
var user = await client.GetAsync<User>("users/123");
var created = await client.PostAsync<User, CreateUserRequest>(newUser, "users");
var updated = await client.PutAsync<User, UpdateUserRequest>(updateUser, "users/123");
var deleted = await client.DeleteAsync("users/123");
This approach allows gradual migration. You can keep your existing implementations working while incrementally adopting v7's functional patterns.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Exhaustion (>= 1.0.0)
- Microsoft.Extensions.Http (>= 8.0.1)
- Outcome (>= 1.0.0)
- System.Text.Json (>= 8.0.5)
- Urls (>= 1.0.0)
-
net8.0
- Exhaustion (>= 1.0.0)
- Microsoft.Extensions.Http (>= 8.0.1)
- Outcome (>= 1.0.0)
- Urls (>= 1.0.0)
-
net9.0
- Exhaustion (>= 1.0.0)
- Microsoft.Extensions.Http (>= 8.0.1)
- Outcome (>= 1.0.0)
- Urls (>= 1.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on RestClient.Net:
| Package | Downloads |
|---|---|
|
CryptoCurrency.Net
Cross platform C# library for general Crypto Currency functionality, and communicating with Cryptocurrency exchanges, and Blockchain APIs. |
|
|
RestClient.Net.DependencyInjection
.NET REST Client Framework for all platforms. This package contains ASP.NET Core DI infrastructure. |
|
|
Relatude.PaymentMethods
Payment methods for Relatude .Net 6.0 version |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.2.1 | 715 | 10/19/2025 |
| 7.2.0 | 130 | 10/19/2025 |
| 7.1.3 | 199 | 10/16/2025 |
| 7.1.2 | 187 | 10/16/2025 |
| 7.1.0 | 197 | 10/16/2025 |
| 7.0.0 | 195 | 10/15/2025 |
| 6.0.0 | 40,921 | 4/12/2023 |
| 5.1.0 | 70,963 | 4/9/2022 |
| 5.0.7 | 60,109 | 5/29/2021 |
| 5.0.6 | 1,949 | 5/26/2021 |
| 5.0.5-beta | 1,360 | 5/15/2021 |
| 5.0.4-beta | 1,845 | 4/26/2021 |
| 5.0.3-beta | 1,369 | 4/24/2021 |
| 5.0.2-alpha | 1,378 | 4/20/2021 |
| 5.0.1-alpha | 1,309 | 4/18/2021 |
| 5.0.0-alpha | 1,349 | 4/4/2021 |
| 4.1.0 | 100,546 | 8/8/2020 |
| 4.0.0 | 33,004 | 6/17/2020 |
| 3.2.0 | 49,267 | 2/11/2020 |
| 3.1.1 | 6,833 | 1/27/2020 |
| 3.1.0 | 3,560 | 1/21/2020 |
| 3.0.0 | 3,935 | 1/3/2020 |
| 2.1.0 | 20,655 | 7/23/2019 |
| 2.0.0 | 45,183 | 4/24/2019 |
| 1.1.0 | 5,168 | 2/15/2019 |
| 1.0.0 | 19,659 | 8/28/2018 |
| 0.8.0 | 6,070 | 6/24/2018 |
| 0.7.0 | 14,443 | 11/25/2017 |
| 0.6.0 | 2,734 | 10/31/2017 |
| 0.5.0 | 3,580 | 6/24/2017 |
| 0.4.0 | 5,274 | 9/3/2016 |
| 0.3.0 | 2,929 | 8/27/2016 |
| 0.2.0 | 3,046 | 8/18/2016 |