Oakrey.Network.Rest 2.0.4

dotnet add package Oakrey.Network.Rest --version 2.0.4
                    
NuGet\Install-Package Oakrey.Network.Rest -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Network.Rest" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Network.Rest" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Network.Rest" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Network.Rest --version 2.0.4
                    
#r "nuget: Oakrey.Network.Rest, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Network.Rest@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Network.Rest&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Network.Rest&version=2.0.4
                    
Install as a Cake Tool

Oakrey.Network.Rest

A .NET library that wraps HttpClient with a reactive observation layer. RestClient exposes GET, POST, PUT, and DELETE over a simple string-based API and publishes every outgoing request and incoming response as IObservable streams.

Main features

  • Get, Post, Put, Delete synchronous convenience methods returning the response body as a string
  • SendData(RestCommand) for command-object-driven dispatch
  • IObservable<HttpResponseMessage> � subscribe to all responses
  • IObservable<HttpRequestMessage> via Requests property � observe all outgoing requests
  • Pluggable content settings via IRestSetting (JsonRestSettings, XmlRestSettings, TextRestSettings)
  • Integrated structured logging via Oakrey.Log
  • Implements IDisposable; disposes both ReplaySubject instances on teardown

Architecture

classDiagram
    class IRestClient {
        <<interface>>
        +Requests IObservable~HttpRequestMessage~
        +Get(url) string
        +Post(url, body) string
        +Put(url, body) string
        +Delete(url) string
        +SendData(RestCommand) string
    }
    class RestClient {
        +RestClient()
        +RestClient(IRestSetting setting)
        +Subscribe(IObserver~HttpResponseMessage~) IDisposable
        +Dispose()
    }
    class IRestSetting {
        <<interface>>
        +Encoding Encoding
        +MediaType string
    }
    class JsonRestSettings
    class XmlRestSettings
    class TextRestSettings
    class RestCommand {
        +Url string
        +Body string
        +Method MethodType
        +Get(url)$ RestCommand
        +Post(url, body)$ RestCommand
        +Put(url, body)$ RestCommand
        +Delete(url)$ RestCommand
    }
    class MethodType {
        <<enumeration>>
        Get
        Post
        Put
        Delete
        Options
        Head
        Trace
        Patch
        Connect
    }
    RestClient ..|> IRestClient
    RestClient --> IRestSetting
    IRestSetting <|.. JsonRestSettings
    IRestSetting <|.. XmlRestSettings
    IRestSetting <|.. TextRestSettings
    RestClient --> RestCommand : dispatches
    RestCommand --> MethodType

Requirements

  • .NET 10 or higher
  • Dependencies (resolved automatically via NuGet):
    • System.Reactive >= 6.1.0
    • Oakrey.Log >= 2.0.0

Installation

.NET CLI

dotnet add package Oakrey.Network.Rest

Package Manager Console

Install-Package Oakrey.Network.Rest

NuGet Package Manager

Search for Oakrey.Network.Rest in Visual Studio under Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

Example usage

Basic HTTP calls

using Oakrey.Network.Rest;

using RestClient client = new();

string body = client.Get("https://api.example.com/items");
string created = client.Post("https://api.example.com/items", """{"name":"widget"}""");
string updated = client.Put("https://api.example.com/items/1", """{"name":"gadget"}""");
string deleted = client.Delete("https://api.example.com/items/1");

Command-object dispatch

RestCommand command = RestCommand.Post("https://api.example.com/items", """{"name":"widget"}""");
string result = client.SendData(command);

Observing responses and requests

// Subscribe to all HTTP responses
using IDisposable responseSub = client.Subscribe(response =>
{
    Console.WriteLine($"Response: {response.StatusCode}");
});

// Subscribe to all outgoing requests
using IDisposable requestSub = client.Requests.Subscribe(request =>
{
    Console.WriteLine($"Request: {request.Method} {request.RequestUri}");
});

Custom content type (JSON)

using RestClient jsonClient = new(new JsonRestSettings());
string response = jsonClient.Post("https://api.example.com/data", """{"key":"value"}""");

Configuration

Setting class MediaType Encoding Notes
TextRestSettings text/plain UTF-8 Default when no setting passed
JsonRestSettings application/json UTF-8
XmlRestSettings application/xml UTF-8

Implement IRestSetting to provide a custom media type or encoding.

Development notes

  • All HTTP calls use .Result to block synchronously on the Task. This is intentional for the current API shape; avoid calling these methods on a UI thread or inside an async context without wrapping in Task.Run.
  • Both ReplaySubject<HttpRequestMessage> and ReplaySubject<HttpResponseMessage> are constructed with a buffer of 1, so a late subscriber receives the most recent item immediately.
  • On any HTTP exception the error is logged via Oakrey.Log and responses.OnError is called, which terminates the response observable for that subscriber.

Project information

License

MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Oakrey.Network.Rest:

Package Downloads
Oakrey.Hue.ApiV1

Model and DTO library for the Philips Hue REST API v1. Provides System.Text.Json-annotated types for lights, state, capabilities, config, streaming, and connection info. No HTTP client included — compose with HttpClient or any REST library.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.4 119 5/22/2026
2.0.3 95 5/15/2026
2.0.2 132 2/2/2026
2.0.1 122 2/2/2026
2.0.0 448 11/18/2025
1.1.0 283 8/28/2025
1.0.0 284 4/17/2025