VitoRestbox 1.2.0

dotnet add package VitoRestbox --version 1.2.0
                    
NuGet\Install-Package VitoRestbox -Version 1.2.0
                    
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="VitoRestbox" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VitoRestbox" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="VitoRestbox" />
                    
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 VitoRestbox --version 1.2.0
                    
#r "nuget: VitoRestbox, 1.2.0"
                    
#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 VitoRestbox@1.2.0
                    
#: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=VitoRestbox&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=VitoRestbox&version=1.2.0
                    
Install as a Cake Tool

πŸ“˜ 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 inspection
  • AfterSend for response handling
  • OnFailure for error tracking
  • OnException for graceful fallback
    βœ… Timeout configuration with .WithTimeout(...)
    βœ… Exception control with .SuppressExceptions(...)
    βœ… Sync and async execution support
    βœ… Works seamlessly with HttpClient 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.0 431 9/21/2025
1.1.0 341 9/21/2025
1.0.0 185 9/19/2025