RestApiClientSharp 1.0.3.1
dotnet add package RestApiClientSharp --version 1.0.3.1
NuGet\Install-Package RestApiClientSharp -Version 1.0.3.1
<PackageReference Include="RestApiClientSharp" Version="1.0.3.1" />
paket add RestApiClientSharp --version 1.0.3.1
#r "nuget: RestApiClientSharp, 1.0.3.1"
// Install RestApiClientSharp as a Cake Addin #addin nuget:?package=RestApiClientSharp&version=1.0.3.1 // Install RestApiClientSharp as a Cake Tool #tool nuget:?package=RestApiClientSharp&version=1.0.3.1
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).
- Prusa: http://www.prusa3d.com/#a_aid=AndreasReitberger *
- Jake3D: https://tidd.ly/3x9JOBp *
- Amazon: https://amzn.to/2Z8PrDu *
- Coinbase: https://advanced.coinbase.com/join/KTKSEBP * (10€ in BTC for you if you open an account)
- TradeRepublic: https://refnocode.trade.re/wfnk80zm * (10€ in stocks for you if you open an account)
(*) Affiliate link Thank you very much for supporting me!
Nuget
Get the latest version from nuget.org<br>
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:
- https://github.com/AndreasReitberger/FinnhubStockApiSharp [in progress...]
- https://github.com/AndreasReitberger/LexOfficeClientSharp [in progress...]
Product | Versions 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. |
-
.NETStandard 2.1
- CommunityToolkit.Mvvm (>= 8.4.0)
- Newtonsoft.Json (>= 13.0.3)
- RestSharp (>= 112.1.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 9.0.1)
- System.Threading.RateLimiting (>= 9.0.1)
-
net8.0
- CommunityToolkit.Mvvm (>= 8.4.0)
- Newtonsoft.Json (>= 13.0.3)
- RestSharp (>= 112.1.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 9.0.1)
- System.Threading.RateLimiting (>= 9.0.1)
-
net9.0
- CommunityToolkit.Mvvm (>= 8.4.0)
- Newtonsoft.Json (>= 13.0.3)
- RestSharp (>= 112.1.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 9.0.1)
- System.Threading.RateLimiting (>= 9.0.1)
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.
Check GitHub releases for changelog.