FluentHttpBuilder 1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FluentHttpBuilder --version 1.0.3
NuGet\Install-Package FluentHttpBuilder -Version 1.0.3
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="FluentHttpBuilder" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentHttpBuilder" Version="1.0.3" />
<PackageReference Include="FluentHttpBuilder" />
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 FluentHttpBuilder --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FluentHttpBuilder, 1.0.3"
#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 FluentHttpBuilder@1.0.3
#: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=FluentHttpBuilder&version=1.0.3
#tool nuget:?package=FluentHttpBuilder&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FluentHttpBuilder
A fluent, type-safe HTTP request builder for .NET 🚀
✨ Features
- 🎯 Fluent API - Easy to read and write
- 🔒 Type-Safe - Compiler protects you from mistakes
- 🌐 All HTTP Methods - GET, POST, PUT, DELETE, PATCH
- 📦 JSON Support - Automatic serialization/deserialization
- 🔑 Authentication - Bearer tokens and custom headers
- ⚙️ Configurable - Timeout, headers, and more
- ❌ Error Handling - Graceful error responses
📦 Installation
dotnet add package FluentHttpBuilder
Or via Package Manager:
Install-Package FluentHttpBuilder
🚀 Quick Start
Simple GET Request
using FluentHttpBuilder;
var response = await HttpRequestBuilder.Create()
.WithUrl("https://jsonplaceholder.typicode.com/posts/1")
.Get()
.SendAsync();
Console.WriteLine($"Status: {response.StatusCode}");
Console.WriteLine($"Content: {response.Content}");
POST Request with JSON
var newPost = new {
title = "My Post",
body = "This is the content",
userId = 1
};
var response = await HttpRequestBuilder.Create()
.WithUrl("https://api.example.com/posts")
.Post()
.WithJsonBody(newPost)
.SendAsync();
if (response.IsSuccess)
{
Console.WriteLine("Post created successfully!");
}
Authenticated Request
var response = await HttpRequestBuilder.Create()
.WithUrl("https://api.example.com/users")
.Get()
.WithBearerToken("your-access-token")
.SendAsync();
Custom Headers & Timeout
var response = await HttpRequestBuilder.Create()
.WithUrl("https://api.example.com/data")
.Get()
.AddHeader("X-Custom-Header", "value")
.AddHeader("X-API-Version", "2.0")
.WithTimeout(60) // 60 seconds
.SendAsync();
📚 API Reference
HTTP Methods
| Method | Description |
|---|---|
Get() |
HTTP GET request |
Post() |
HTTP POST request (requires body) |
Put() |
HTTP PUT request (requires body) |
Delete() |
HTTP DELETE request |
Patch() |
HTTP PATCH request (requires body) |
Configuration Methods
| Method | Description |
|---|---|
WithUrl(string) |
Set the request URL (required) |
WithJsonBody<T>(T) |
Add JSON body (auto-serialized) |
WithBody(string, contentType) |
Add custom body |
WithBearerToken(string) |
Add Bearer authentication |
AddHeader(key, value) |
Add custom header |
WithTimeout(int) |
Set timeout in seconds |
SendAsync() |
Execute the request |
Build() |
Build request without executing |
🎯 Advanced Examples
PUT Request
var updateData = new {
title = "Updated Title",
completed = true
};
var response = await HttpRequestBuilder.Create()
.WithUrl("https://api.example.com/posts/1")
.Put()
.WithJsonBody(updateData)
.WithBearerToken("token")
.SendAsync();
DELETE Request
var response = await HttpRequestBuilder.Create()
.WithUrl("https://api.example.com/posts/1")
.Delete()
.WithBearerToken("token")
.SendAsync();
Console.WriteLine(response.IsSuccess ? "Deleted!" : "Failed");
Build Without Executing (for testing)
var request = HttpRequestBuilder.Create()
.WithUrl("https://api.example.com/data")
.Post()
.WithJsonBody(new { test = "data" })
.Build();
Console.WriteLine($"Will send {request.Method} to {request.Url}");
Console.WriteLine($"Body: {request.Body}");
🔧 Response Object
public class FluentHttpResponse
{
public int StatusCode { get; init; } // HTTP status code (200, 404, etc.)
public string Content { get; init; } // Response body as string
public bool IsSuccess { get; init; } // True if 2xx status
public Dictionary<string, string> Headers { get; init; } // Response headers
}
💡 Best Practices
- Reuse HttpClient - The builder uses a static HttpClient internally
- Handle Errors - Always check
response.IsSuccess - Set Timeouts - For slow APIs, increase timeout
- Use Async/Await - All methods are async
⚠️ Error Handling
var response = await HttpRequestBuilder.Create()
.WithUrl("https://api.example.com/data")
.Get()
.SendAsync();
if (!response.IsSuccess)
{
Console.WriteLine($"Error: {response.StatusCode}");
Console.WriteLine($"Message: {response.Content}");
}
🤝 Contributing
Contributions are welcome! Feel free to:
- Report bugs
- Suggest features
- Submit pull requests
📄 License
MIT License - feel free to use in your projects!
🔗 Links
📞 Support
For questions or support, please open an issue on GitHub.
Made with ❤️ for the .NET community
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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.
-
net8.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.