AsthaIT.RestClient 1.0.0

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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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