A lightweight .NET library that provides useful extensions for HTTP operations, including JSON serialization/deserialization, HTTP client factory helpers, and API client abstractions.
- HttpContent Extensions: Easy JSON deserialization from HTTP responses
- HttpClient Extensions: Simplified HTTP operations with automatic JSON serialization
- HttpClientFactory Extensions: Streamlined client creation with authentication and base address setup
- API Client Framework: Base classes and builders for creating structured API clients
- JWT Token Support: Built-in JWT authentication helpers
- Service Collection Extensions: Easy dependency injection setup
Install via NuGet Package Manager:
dotnet add package SimplyWorks.HttpExtensionsOr via Package Manager Console:
Install-Package SimplyWorks.HttpExtensionsusing SW.HttpExtensions;
// Deserialize JSON response to strongly typed object
var response = await httpClient.GetAsync("api/users");
var users = await response.Content.ReadAsAsync<List<User>>();using SW.HttpExtensions;
// POST with automatic JSON serialization
var user = new User { Name = "John", Email = "john@example.com" };
var response = await httpClient.PostAsync("api/users", user);
// POST with automatic deserialization
var createdUser = await httpClient.PostAsync<User>("api/users", user);
// GET with automatic deserialization
var users = await httpClient.GetAsync<List<User>>("api/users");
// PUT with automatic JSON serialization
await httpClient.PutAsync("api/users/1", user);using SW.HttpExtensions;
// Create client with base address and JWT authentication
var client = httpClientFactory.CreateClient(
new Uri("https://api.example.com"),
jwt: "your-jwt-token"
);using SW.HttpExtensions;
// Add JWT token parameters from configuration
services.AddJwtTokenParameters(options =>
{
// Configure JWT options
});
// Add API client with options
services.AddApiClient<IUserApi, UserApiClient, UserApiMock, UserApiOptions>(options =>
{
options.BaseUrl = "https://api.example.com";
options.Mock = false;
});- .NET 8.0
- Microsoft.AspNetCore.Http.Abstractions (≥2.3.0)
- Microsoft.Extensions.Configuration.Binder (≥8.0.2)
- Microsoft.Extensions.Http (≥8.0.1)
- Newtonsoft.Json (≥13.0.3)
- SimplyWorks.PrimitiveTypes (≥8.0.0)
- System.IdentityModel.Tokens.Jwt (≥8.3.1)
This project is licensed under the MIT License - see the LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any bugs or have feature requests, please submit an issue.