AsthaIT.RestClient
1.0.0
dotnet add package AsthaIT.RestClient --version 1.0.0
NuGet\Install-Package AsthaIT.RestClient -Version 1.0.0
<PackageReference Include="AsthaIT.RestClient" Version="1.0.0" />
<PackageVersion Include="AsthaIT.RestClient" Version="1.0.0" />
<PackageReference Include="AsthaIT.RestClient" />
paket add AsthaIT.RestClient --version 1.0.0
#r "nuget: AsthaIT.RestClient, 1.0.0"
#addin nuget:?package=AsthaIT.RestClient&version=1.0.0
#tool nuget:?package=AsthaIT.RestClient&version=1.0.0
AIT.Packages.RestClient
A lightweight and easy-to-use HTTP client for .NET applications that provides a clean interface for making HTTP requests. This package simplifies API integrations by providing strongly-typed responses and a fluent API design.
Features
- Strongly typed requests and responses
- Support for all major HTTP methods (GET, POST, PUT, PATCH, DELETE)
- Form data support for POST requests
- Custom header support
- Cancellation token support
- JSON serialization with enum support
Installation
dotnet add package AsthaIT.RestClient
Usage
First, add the necessary using statement:
using AIT.Packages.RestClient;
using AIT.Packages.RestClient.Response;
Making Requests
GET Request
// Simple GET request
var response = await AITRestClient.GetAsync<UserDto>("https://api.example.com/users/1");
// GET request with custom headers
var headers = new Dictionary<string, string>
{
{ "Authorization", "Bearer your-token" },
{ "Accept", "application/json" }
};
var response = await AITRestClient.GetAsync<UserDto>(
"https://api.example.com/users/1",
headers
);
if (response.IsSuccess)
{
var user = response.Data;
Console.WriteLine($"User name: {user.Name}");
}
POST Request with JSON Body
// Request model
var newUser = new CreateUserDto
{
Name = "John Doe",
Email = "john@example.com"
};
// Simple POST request
var response = await AITRestClient.PostAsync<CreateUserDto, UserDto>(
"https://api.example.com/users",
newUser
);
// POST with headers
var headers = new Dictionary<string, string>
{
{ "Authorization", "Bearer your-token" }
};
var response = await AITRestClient.PostAsync<CreateUserDto, UserDto>(
"https://api.example.com/users",
newUser,
headers
);
POST Request with Form Data
var formData = new Dictionary<string, object>
{
{ "username", "johndoe" },
{ "password", "secretpassword" },
{ "remember", true }
};
var response = await AITRestClient.PostAsync<LoginResponseDto>(
"https://api.example.com/login",
formData
);
PUT Request
var updateUser = new UpdateUserDto
{
Name = "John Updated",
Email = "john.updated@example.com"
};
var response = await AITRestClient.PutAsync<UpdateUserDto, UserDto>(
"https://api.example.com/users/1",
updateUser
);
PATCH Request
var patchUser = new PatchUserDto
{
Name = "John Patched"
};
var response = await AITRestClient.PatchAsync<PatchUserDto, UserDto>(
"https://api.example.com/users/1",
patchUser
);
DELETE Request
var response = await AITRestClient.DeleteAsync<DeleteResponseDto>(
"https://api.example.com/users/1"
);
Working with Responses
All requests return an APIResponse<T>
object that contains:
public class APIResponse<T>
{
public bool IsSuccess { get; set; } // Indicates if the request was successful
public HttpStatusCode StatusCode { get; set; } // The HTTP status code
public T? Data { get; set; } // The response data (if any)
public string? ErrorMessage { get; set; } // The error message (if any)
}
Example of handling responses:
var response = await AITRestClient.GetAsync<UserDto>("https://api.example.com/users/1");
if (response.IsSuccess)
{
var user = response.Data;
Console.WriteLine($"Successfully retrieved user: {user.Name}");
}
else
{
Console.WriteLine("StatusCode: {response.StatusCode}");
Console.WriteLine("ErrorMessage: {response.ErrorMessage}");
}
License
MIT License
Author
Developed and maintained by AIT.
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 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. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on AsthaIT.RestClient:
Package | Downloads |
---|---|
AsthaIT.SocialLogin
AsthaIT.SocialLogin is a simple and extensible library for integrating social login functionality (Google, Facebook, Github.) into .NET Core applications. It streamlines OAuth setup, handles authentication flows securely, and provides user information with minimal configuration. |
|
AsthaIT.SMSGateway
This package belongs to all of our SMS gateways. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 184 | 6/2/2025 |