OutWit.Common.Rest
1.0.0
dotnet add package OutWit.Common.Rest --version 1.0.0
NuGet\Install-Package OutWit.Common.Rest -Version 1.0.0
<PackageReference Include="OutWit.Common.Rest" Version="1.0.0" />
paket add OutWit.Common.Rest --version 1.0.0
#r "nuget: OutWit.Common.Rest, 1.0.0"
// Install OutWit.Common.Rest as a Cake Addin #addin nuget:?package=OutWit.Common.Rest&version=1.0.0 // Install OutWit.Common.Rest as a Cake Tool #tool nuget:?package=OutWit.Common.Rest&version=1.0.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. |
-
net6.0
- Newtonsoft.Json (>= 13.0.3)
- OutWit.Common (>= 1.0.2)
-
net7.0
- Newtonsoft.Json (>= 13.0.3)
- OutWit.Common (>= 1.0.2)
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- OutWit.Common (>= 1.0.2)
-
net9.0
- Newtonsoft.Json (>= 13.0.3)
- OutWit.Common (>= 1.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 91 | 1/2/2025 |