VitoRestbox 1.2.0
dotnet add package VitoRestbox --version 1.2.0
NuGet\Install-Package VitoRestbox -Version 1.2.0
<PackageReference Include="VitoRestbox" Version="1.2.0" />
<PackageVersion Include="VitoRestbox" Version="1.2.0" />
<PackageReference Include="VitoRestbox" />
paket add VitoRestbox --version 1.2.0
#r "nuget: VitoRestbox, 1.2.0"
#:package VitoRestbox@1.2.0
#addin nuget:?package=VitoRestbox&version=1.2.0
#tool nuget:?package=VitoRestbox&version=1.2.0
π VitoRestbox
VitoRestbox is a clean, expressive HTTP request builder for .NET, designed to simplify REST API calls and enrich your application's communication with external services. Inspired by the Latin word vita (βlifeβ), this library brings clarity, vitality, and composability to your HTTP interactions.
β¨ Features
β
Fluent, sentence-like API for building HTTP requests
β
Supports all HTTP verbs: GET
, POST
, PUT
, PATCH
, DELETE
β
Built-in JSON serialization with customizable options
β
Header and authentication injection
β
Flexible .WithHeaders(...)
builder pattern
β
Lifecycle hooks:
BeforeSend
for request inspectionAfterSend
for response handlingOnFailure
for error trackingOnException
for graceful fallback
β Timeout configuration with.WithTimeout(...)
β Exception control with.SuppressExceptions(...)
β Sync and async execution support
β Works seamlessly withHttpClient
and DI containers
β Multipart file upload support via.PostMultipart(...)
,.PutMultipart(...)
,.PatchMultipart(...)
β Multi-framework compatibility: supports.NET 5
,.NET 6
,.NET 7
,.NET 8
,.NET 9
π Quick Start
var result = await VitoRestboxRequest
.New(httpClient)
.To("https://api.example.com/users")
.WithBearerToken("your-token")
.WithHeader("X-Custom", "value")
.Post(new { name = "Reza" })
.SendAsync<UserResponse>();
var result = await VitoRestboxRequest
.New(httpClient)
.To("https://api.example.com/users")
.WithBearerToken("your-token")
.WithHeader("X-Custom", "value")
.Post(new { name = "Reza" })
.WithTimeout(10)
.SuppressExceptions()
.BeforeSend(req => Console.WriteLine($"Sending: {req.RequestUri}"))
.AfterSend(res => Console.WriteLine($"Status: {res.StatusCode}"))
.OnFailure(res => Console.WriteLine($"Failed: {res.StatusCode}"))
.OnException(ex => Console.WriteLine($"Error: {ex.Message}"))
.SendAsync<UserResponse>();
π€ File Uploads
VitoRestbox supports multipart file uploads using .PostMultipart(...)
, .PutMultipart(...)
, and .PatchMultipart(...)
. You can send files, form fields, and binary content with ease:
await VitoRestboxRequest
.New(httpClient)
.To("api/upload")
.PostMultipart(form =>
{
form.Add(new StringContent("Reza"), "username");
form.Add(new ByteArrayContent(fileBytes), "file", "hello.txt");
})
.SendAsync<UploadResponse>();
You can also simulate real IFormFile
uploads in tests:
FormFile formFile = await GetFileAsync();
var result = await VitoRestboxRequest
.New(httpClient)
.To("api/upload")
.PostMultipart(form =>
{
form.Add(new StringContent("Reza"), "username");
form.Add(new StreamContent(formFile.OpenReadStream()), "file", formFile.FileName);
})
.SendAsync<UploadResponseModel>();
π§ Fluent Header Builder
Inject multiple headers using chained or multiple lambdas:
.WithHeaders
(
h => h.Add("Authorization", "Bearer xyz"),
h => h.Add("X-Request-ID", Guid.NewGuid().ToString())
)
Or use a single chained builder:
.WithHeaders(h => h.Add("Authorization", "Bearer xyz").Add("X-Request-ID", Guid.NewGuid().ToString()))
β± Timeout & Exception Control
Set a timeout for the request:
.WithTimeout(15) // Timeout after 15 seconds
Suppress exceptions and handle failures manually:
.SuppressExceptions() // Prevents exceptions from being thrown
π§ͺ Testing
VitoRestbox is fully testable with xUnit
, FluentAssertions
, and custom HttpMessageHandler
mocks. You can simulate file uploads, lifecycle hooks, and error handling with ease.
β Sample: Uploading a File in Test
[Fact]
public async Task Should_Upload_Text_File_SuccessfullyAsync()
{
FormFile formFile = await GetFileAsync();
var result = await VitoRestboxRequest
.New(_client)
.To("api/upload")
.PostMultipart(form =>
{
form.Add(new StringContent("Reza"), "username");
form.Add(new StreamContent(formFile.OpenReadStream()), "file", formFile.FileName);
})
.SendAsync<UploadResponseModel>();
Assert.NotNull(result);
Assert.Equal("File uploaded successfully.", result.Message);
Assert.Equal("hello.txt", result.FileName);
Assert.Equal("Reza", result.Username);
}
π Framework Compatibility
VitoRestbox supports the following target frameworks:
.NET 5.0
.NET 6.0
.NET 7.0
.NET 8.0
.NET 9.0
Package dependencies are conditionally resolved to avoid conflicts across versions. This ensures smooth installation and runtime stability regardless of your projectβs target.
π¦ Installation
dotnet add package VitoRestbox
Or via NuGet Package Manager:
Install-Package VitoRestbox
π Philosophy
In Latin, vita means "life"βand VitoRestbox aims to bring life to your API calls by making HTTP communication readable, composable, and expressive. Whether you're building microservices, SDKs, or internal tools, this library helps you express intent and outcome with precision.
π€ Author
Reza Ghadimi
π LinkedIn
π GitHub Profile
π¦ VitoRestbox Repository
π License
MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. 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 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. |
-
net5.0
- Microsoft.Extensions.Http (>= 5.0.0)
-
net6.0
- Microsoft.Extensions.Http (>= 6.0.1)
-
net7.0
- Microsoft.Extensions.Http (>= 7.0.0)
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.1)
-
net9.0
- Microsoft.Extensions.Http (>= 9.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.