FluentRestClient 1.1.3
dotnet add package FluentRestClient --version 1.1.3
NuGet\Install-Package FluentRestClient -Version 1.1.3
<PackageReference Include="FluentRestClient" Version="1.1.3" />
<PackageVersion Include="FluentRestClient" Version="1.1.3" />
<PackageReference Include="FluentRestClient" />
paket add FluentRestClient --version 1.1.3
#r "nuget: FluentRestClient, 1.1.3"
#:package FluentRestClient@1.1.3
#addin nuget:?package=FluentRestClient&version=1.1.3
#tool nuget:?package=FluentRestClient&version=1.1.3
FluentRestClient
A lightweight, fluent, and extensible REST client wrapper for .NET, designed to simplify API requests with support for features like MessagePack, configurable headers, and easy request customization.
๐ Features
- Fluent request building syntax
- Supports JSON and MessagePack serialization
- Multipart/form-data support for file uploads
- Cancellation token support
- Custom headers, query parameters, and request options
- Strongly typed responses
- Lightweight and dependency-free
๐ฆ Installation
Install via NuGet:
dotnet add package FluentRestClient
Or via the NuGet Package Manager:
Install-Package FluentRestClient
๐ ๏ธ Usage
var response = await RequestBuilder
.Create(HttpMethod.Get, "https://api.example.com/items")
.WithHeader("Authorization", "Bearer YOUR_TOKEN")
.WithQuery("page", "1")
.SendAsync<ApiResponse<List<ItemDto>>>(httpClient, cancellationToken);
Or with MessagePack serialization:
var response = await RequestBuilder
.Create(HttpMethod.Get, "https://api.example.com/items")
.WithMessagePackEnabled()
.SendAsync<List<ItemDto>>(httpClient, cancellationToken);
File Upload with Multipart/Form-Data
Upload files using multipart/form-data:
// Upload a single file
byte[] fileBytes = File.ReadAllBytes("document.pdf");
var response = await RequestBuilder
.Create(HttpMethod.Post, "https://api.example.com/upload")
.WithFile("file", fileBytes, "document.pdf", "application/pdf")
.WithFormField("description", "My document")
.SendAsync<UploadResponse>(httpClient, cancellationToken);
Or upload using a file stream:
using var fileStream = File.OpenRead("image.jpg");
var response = await RequestBuilder
.Create(HttpMethod.Post, "https://api.example.com/upload")
.WithFileStream("image", fileStream, "image.jpg", "image/jpeg")
.WithFormField("title", "Profile Picture")
.SendAsync<UploadResponse>(httpClient, cancellationToken);
Upload multiple files:
var response = await RequestBuilder
.Create(HttpMethod.Post, "https://api.example.com/upload-multiple")
.WithFile("file1", file1Bytes, "doc1.pdf", "application/pdf")
.WithFile("file2", file2Bytes, "doc2.pdf", "application/pdf")
.WithFormField("category", "documents")
.SendAsync<UploadResponse>(httpClient, cancellationToken);
โจ Example API
public Task<ApiResponse<List<UserItem>>?> UsersList(CancellationToken cancellationToken = default)
=> RequestBuilder.Create(HttpMethod.Get, Urls.GetUsersList)
.SendAsync<ApiResponse<List<UserItem>>>(_restClient, cancellationToken);
๐ Documentation
-[x] Fluent API for building REST requests
-[x] Custom serialization options
-[ ] Optional retry policies (coming soon)
๐งฉ Extensibility
You can extend the RequestBuilder to add:
Global headers
Authentication middleware
Logging
Retry policies (e.g., Polly)
๐งช Testing
Mock IHttpClientFactory for unit tests.
๐ค Contributing
Pull requests are welcome! Feel free to fork the repo and submit improvements.
๐ License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net9.0
- MessagePack (>= 3.1.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.