HttpStudio 1.0.0

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

HttpStudio

A lightweight, developer-friendly wrapper around HttpClient that simplifies making HTTP requests (GET, POST, PUT, PATCH, DELETE, File Uploads, and File Downloads) in .NET.

It provides generic response handling, header support, file uploads/downloads, and consistent error handling using a custom HttpHelperException.


🚀 Installation

Install via NuGet Package Manager:

dotnet add package HttpStudio

Or in Visual Studio Package Manager Console:

Install-Package HttpStudio

📖 Quick Start

🔹 ASP.NET Core (Dependency Injection)

Register HttpHelper in your DI container:

builder.Services.AddHttpClient<HttpHelper>(client =>
{
    client.BaseAddress = new Uri("https://yourapiurl/");
});

Inject and use it:

public class UserService
{
    private readonly HttpHelper _httpHelper;

    public UserService(HttpHelper httpHelper)
    {
        _httpHelper = httpHelper;
    }

    public async Task GetUserAsync()
    {
        var user = await _httpHelper.GetAsync<User>("users/1");
        Console.WriteLine(user.Name);
    }
}

🔹 Console App (Without Dependency Injection)

using HttpStudio;

class Program
{
    static async Task Main(string[] args)
    {
        using var httpClient = new HttpClient
        {
            BaseAddress = new Uri("https://yourapiurl/")
        };

        var httpHelper = new HttpHelper(httpClient);

        var userJson = await httpHelper.GetAsync<string>("users/1");
        Console.WriteLine(userJson);
    }
}

⚡ Features & Usage

🔄 Generic Response Handling

  • Get raw JSON/string
  • Or deserialize directly into your own models
// Raw string
var userJson = await httpHelper.GetAsync<string>("users/1");

// Strongly-typed
var user = await httpHelper.GetAsync<User>("users/1");
Console.WriteLine(user.Name);

👉 Works across GET, POST, PUT, PATCH, DELETE


✅ Supported Methods

GET
var user = await httpHelper.GetAsync<User>("users/1");
POST (JSON body)
var result = await httpHelper.PostAsync<User, object>(
    "users",
    new { Name = "Bhai Shahb", Email = "test@email.com" }
);
PUT
var updated = await httpHelper.PutAsync<User, User>("users/1", updatedUser);
PATCH
var patched = await httpHelper.PatchAsync<User, object>(
    "users/1",
    new { Name = "Updated Name" }
);
DELETE
var response = await httpHelper.DeleteAsync<string>("users/1");

📤 Multipart Form-Data (File Uploads)

using var fileStream = File.OpenRead("photo.png");

var result = await httpHelper.PostFormDataAsync(
    "upload",
    formFields: new Dictionary<string, string>
    {
        { "userId", "123" }
    },
    files: new List<(string, string, Stream, string)>
    {
        ("file", "photo.png", fileStream, "image/png")
    }
);

📥 File Download

Save to Disk
await httpHelper.DownloadFileAsync(
    "files/report.pdf",
    "C:/Downloads/report.pdf"
);
Stream the File (without saving)
using var stream = await httpHelper.DownloadFileAsStreamAsync("files/report.pdf");
// Forward stream to browser, cloud storage, etc.

📝 Headers

Both single-value and multi-value headers are supported:

var headers = new Dictionary<string, string>
{
    { "Authorization", "Bearer my-jwt-token" }
};

var multiHeaders = new Dictionary<string, IEnumerable<string>>
{
    { "Accept", new[] { "application/json", "text/plain" } }
};

var response = await httpHelper.GetAsync<string>(
    "users/1",
    headers,
    multiHeaders
);

⏳ Cancellation Tokens

Every method supports cancellation:

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var user = await httpHelper.GetAsync<User>("users/1", cancellationToken: cts.Token);

⚠️ Error Handling

All methods throw a HttpHelperException when:

  • The server returns a non-success status code
  • The response cannot be deserialized
  • Network issues or timeouts occur

Example:

try
{
    var user = await httpHelper.GetAsync<User>("users/999");
}
catch (HttpHelperException ex)
{
    Console.WriteLine($"Error: {ex.Message}, Status: {ex.StatusCode}");
    Console.WriteLine($"Response: {ex.ResponseBody}");
}

✅ Benefits

  • 🚫 No more HttpClient boilerplate
    Simple methods for GET, POST, PUT, PATCH, DELETE.

  • 🔄 Flexible generic responses
    Return raw JSON (string) or deserialize into typed objects.

  • 📦 File uploads via multipart/form-data
    Upload files along with additional form fields.

  • 📥 File downloads
    Save directly to disk or return as a stream.

  • 📝 Full header control
    Add single or multi-value headers to requests.

  • Cancellation & timeout support
    All methods accept CancellationToken.

  • Consistent exception handling
    All failures throw HttpHelperException with status code, content, and inner error.

  • 🧩 Works in ASP.NET Core (with DI) or Console Apps
    Just inject or pass an HttpClient instance.


📌 Requirements

  • .NET 6.0 or later
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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.
  • net7.0

    • No dependencies.

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 158 9/5/2025

First release to use this package for your internal proejcts.
Open for suggestions and issues.