OutWit.Common.Rest
1.2.0
dotnet add package OutWit.Common.Rest --version 1.2.0
NuGet\Install-Package OutWit.Common.Rest -Version 1.2.0
<PackageReference Include="OutWit.Common.Rest" Version="1.2.0" />
<PackageVersion Include="OutWit.Common.Rest" Version="1.2.0" />
<PackageReference Include="OutWit.Common.Rest" />
paket add OutWit.Common.Rest --version 1.2.0
#r "nuget: OutWit.Common.Rest, 1.2.0"
#:package OutWit.Common.Rest@1.2.0
#addin nuget:?package=OutWit.Common.Rest&version=1.2.0
#tool nuget:?package=OutWit.Common.Rest&version=1.2.0
OutWit.Common.Rest
Overview
OutWit.Common.Rest is a robust library designed to simplify and streamline HTTP client interactions in .NET applications. By leveraging a modular and extensible architecture, it offers powerful abstractions for building and executing RESTful requests, handling responses, and managing query parameters with ease.
Features
1. Query Builder
The QueryBuilder class provides a fluent API for constructing URL query strings dynamically. It supports multiple parameter types, including primitives, enumerations, and collections.
Example Usage
var queryBuilder = new QueryBuilder()
.AddParameter("name", "John Doe")
.AddParameter("age", 30)
.AddParameter("tags", new[] { "developer", "blogger" });
string query = await queryBuilder.AsStringAsync();
Console.WriteLine(query); // Output: name=John%20Doe&age=30&tags=developer,blogger
2. REST Client
The RestClient class provides an abstraction for HTTP operations, including GET, POST, and SEND requests. It simplifies common tasks like deserialization and content creation while allowing advanced configuration with fluent methods.
Example Usage
var client = RestClientBuilder.Create()
.WithBearer("your-token")
.WithHeader("Custom-Header", "HeaderValue");
var result = await client.GetAsync<MyResponseType>("https://api.example.com/resource");
3. Exception Handling
The RestClientException class encapsulates HTTP status codes and response content, making error handling intuitive and detailed.
Example
try
{
var result = await client.GetAsync<MyResponseType>("https://api.example.com/invalid-resource");
}
catch (RestClientException ex)
{
Console.WriteLine($"Error: {ex.StatusCode}, Content: {ex.Content}");
}
4. Serialization and Deserialization
Integrated with Newtonsoft.Json, the library supports efficient serialization and deserialization of request and response content.
Deserialize Example
var response = await httpResponseMessage.DeserializeAsync<MyResponseType>();
5. Builder Utilities
The library includes utilities for building requests with advanced features like:
- Custom authorization headers
- Content serialization
- Dynamic query parameter handling
Installation
Install the package via NuGet:
Install-Package OutWit.Common.Rest
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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 is compatible. 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 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
- OutWit.Common (>= 1.3.0)
-
net6.0
- OutWit.Common (>= 1.3.0)
-
net7.0
- OutWit.Common (>= 1.3.0)
-
net8.0
- OutWit.Common (>= 1.3.0)
-
net9.0
- OutWit.Common (>= 1.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OutWit.Common.Rest:
| Package | Downloads |
|---|---|
|
OutWit.Communication.Client.Rest
REST transport client for WitRPC, allowing communication with a WitRPC server over HTTP (RESTful) calls - ideal for integrating with web services or non-.NET clients. |
GitHub repositories
This package is not used by any popular GitHub repositories.