TheNevix.Utils.RequestHandler 1.1.0-beta-240812-4

This is a prerelease version of TheNevix.Utils.RequestHandler.
There is a newer version of this package available.
See the version list below for details.
dotnet add package TheNevix.Utils.RequestHandler --version 1.1.0-beta-240812-4                
NuGet\Install-Package TheNevix.Utils.RequestHandler -Version 1.1.0-beta-240812-4                
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="TheNevix.Utils.RequestHandler" Version="1.1.0-beta-240812-4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TheNevix.Utils.RequestHandler --version 1.1.0-beta-240812-4                
#r "nuget: TheNevix.Utils.RequestHandler, 1.1.0-beta-240812-4"                
#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.
// Install TheNevix.Utils.RequestHandler as a Cake Addin
#addin nuget:?package=TheNevix.Utils.RequestHandler&version=1.1.0-beta-240812-4&prerelease

// Install TheNevix.Utils.RequestHandler as a Cake Tool
#tool nuget:?package=TheNevix.Utils.RequestHandler&version=1.1.0-beta-240812-4&prerelease                

TheNevix.Utils.RequestHandler

NuGet NuGet Downloads

A simple and flexible HTTP request handler utility for .NET applications. This library simplifies making API calls by providing an easy-to-use interface for sending HTTP requests with optional headers and handling responses.

Features

  • Simplified API for making HTTP requests
  • Support for adding custom headers
  • Built-in error handling and response validation
  • Supports .NET 6.0, 7.0, and 8.0

Installation

You can install the package via NuGet Package Manager, .NET CLI, or by adding it to your project file.

NuGet Package Manager

Install-Package TheNevix.Utils.RequestHandler

Configuration

Enable the RequestHandler in your program.cs file.

builder.Services.AddRequestHandlerServices();

Usage

This is an example of a basic GET request.

public class SomeService
{
    private readonly IRequestHandler _requestHandler;

    public SomeService(IRequestHandler requestHandler)
    {
        _requestHandler = requestHandler;
    }

    public async Task DoSomethingAsync(string url)
    {
        var response = await _requestHandler.GetAsync(url);
        // Process the response
    }
}

All methods either return a JSON string as a result of the request or an exception.

Here's an example to pass headers to the GET request.

public class SomeService
{
    private readonly IRequestHandler _requestHandler;

    public SomeService(IRequestHandler requestHandler)
    {
        _requestHandler = requestHandler;
    }

    public async Task DoSomethingAsync(string url)
    {
        var someHeaders = new Dictionary<string, string>
        {
            { "Authorization", "Bearer ey..." }
        };

        var someRequestOptions = new RequestHandlerOptions(someHeaders);

        var response = await _requestHandler.GetAsync(url, someRequestOptions);
        // Process the response
    }
}

This example applies for a methods, except for PUT, PATCH and POST. These methods also expect a body.

Notes

Since I don't really use the DELETE request I have left it out for now. It will be added in the near future.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.4 0 12/2/2024
1.1.3 0 12/2/2024
1.1.2 0 12/2/2024
1.1.1 18 12/2/2024
1.1.0 132 8/14/2024
1.1.0-beta-240813 113 8/13/2024
1.1.0-beta-240812-4 100 8/12/2024
1.1.0-beta-240812-3 102 8/12/2024
1.1.0-alpha-240812-2 104 8/12/2024
1.1.0-alpha-240812 107 8/12/2024
1.0.0 134 8/10/2024

Beta version of 1.1.0.