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
<PackageReference Include="Oakrey.Network.Rest" Version="2.0.4" />
<PackageVersion Include="Oakrey.Network.Rest" Version="2.0.4" />
<PackageReference Include="Oakrey.Network.Rest" />
paket add Oakrey.Network.Rest --version 2.0.4
#r "nuget: Oakrey.Network.Rest, 2.0.4"
#:package Oakrey.Network.Rest@2.0.4
#addin nuget:?package=Oakrey.Network.Rest&version=2.0.4
#tool nuget:?package=Oakrey.Network.Rest&version=2.0.4
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,Deletesynchronous convenience methods returning the response body as a stringSendData(RestCommand)for command-object-driven dispatchIObservable<HttpResponseMessage>� subscribe to all responsesIObservable<HttpRequestMessage>viaRequestsproperty � observe all outgoing requests- Pluggable content settings via
IRestSetting(JsonRestSettings,XmlRestSettings,TextRestSettings) - Integrated structured logging via
Oakrey.Log - Implements
IDisposable; disposes bothReplaySubjectinstances 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.0Oakrey.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
.Resultto block synchronously on theTask. This is intentional for the current API shape; avoid calling these methods on a UI thread or inside an async context without wrapping inTask.Run. - Both
ReplaySubject<HttpRequestMessage>andReplaySubject<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.Logandresponses.OnErroris called, which terminates the response observable for that subscriber.
Project information
- Author: Oakrey
- License: MIT
- NuGet: Oakrey.Network.Rest
- Repository: Azure DevOps
License
MIT License. See the LICENSE file for details.
| Product | Versions 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. |
-
net10.0
- Oakrey.Log (>= 2.0.1)
- System.Reactive (>= 6.1.0)
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.