RestApiClientSharp 1.0.2

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

// Install RestApiClientSharp as a Cake Tool
#tool nuget:?package=RestApiClientSharp&version=1.0.2                

RestApiClientSharp

Is a common library for a REST API client solution.

Support me

If you want to support me, you can order over following affilate links (I'll get a small share from your purchase from the corresponding store).

(*) Affiliate link Thank you very much for supporting me!

Nuget

Get the latest version from nuget.org<br> NuGet NuGet

How to use

Available REST functions

public virtual async Task<IRestApiRequestRespone?> SendRestApiRequestAsync(...);
public virtual async Task<IRestApiRequestRespone?> SendMultipartFormDataFileRestApiRequestAsync(...);
public virtual async Task<byte[]?> DownloadFileFromUriAsync(...);

SendRestApiRequestAsync()

This function allows you to send a simple REST request to your REST-API-Server endpoint. If succeeded, you can access the received string and byte[] as followed.

IRestApiRequestRespone.Result
IRestApiRequestRespone.RawBytes

SendMultipartFormDataFileRestApiRequestAsync()

This function allows you to send a multi form data REST request to your REST-API-Server endpoint. If succeeded, you can access the received string and byte[], the same as with the SendRestApiRequestAsync() function.

DownloadFileFromUriAsync()

This function allows you to download a file as byte[].

Integration

You just can inherit from the RestApiClient class to get access to all common REST functions of our client.

public partial class MyCustomRestClient : RestApiClient
{
    #region Constructor
    public MyCustomRestClient() : base() 
    { }
    
    public MyCustomRestClient(string apiKey, string tokenName = "token") : base(
        new AuthenticationHeader() { Token = apiKey, Target = AuthenticationHeaderTarget.UrlSegment},
        tokenName) 
    { }
    
    public MyCustomRestClient(string webAddress, string apiKey, string tokenName = "token") : base(
        new AuthenticationHeader() { Token = apiKey, Target = AuthenticationHeaderTarget.UrlSegment },
        tokenName, webAddress)
    { }
    #endregion
}

Example of communication

public async Task<StockQuoteResult?> GetStockQuoteAsync(string symbol)
{
    IRestApiRequestRespone? result = null;
    StockQuoteResult? resultObject = null;
    Dictionary<string, string> parameters = [];
    try
    {
        if (!string.IsNullOrEmpty(symbol)) parameters.Add("symbol", symbol);
        string targetUri = $"";
        result = await SendRestApiRequestAsync(
               requestTargetUri: targetUri,
               method: Method.Get,
               command: "quote",
               jsonObject: null,
               authHeaders: AuthHeaders,
               // Parameters
               urlSegments: parameters,
               cts: default
               )
            .ConfigureAwait(false);
        resultObject = GetObjectFromJson<StockQuoteResult>(result?.Result, NewtonsoftJsonSerializerSettings);
        return resultObject;
    }
    catch (Exception exc)
    {
        OnError(new UnhandledExceptionEventArgs(exc, false));
        return resultObject;
    }
}

You will find some complete, production examples here:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on RestApiClientSharp:

Package Downloads
Print3dServer.Core

A C# based core library for our 3d Print Server nugets (Moonraker, Repetier Server, OctoPrint and so on).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3.1 45 1/30/2025
1.0.3 33 1/30/2025
1.0.2 45 1/27/2025
1.0.1 132 1/21/2025
1.0.0 70 12/19/2024

Check GitHub releases for changelog.