Shard.Requests
0.1.1
See the version list below for details.
dotnet add package Shard.Requests --version 0.1.1
NuGet\Install-Package Shard.Requests -Version 0.1.1
<PackageReference Include="Shard.Requests" Version="0.1.1" />
paket add Shard.Requests --version 0.1.1
#r "nuget: Shard.Requests, 0.1.1"
// Install Shard.Requests as a Cake Addin #addin nuget:?package=Shard.Requests&version=0.1.1 // Install Shard.Requests as a Cake Tool #tool nuget:?package=Shard.Requests&version=0.1.1
Requests
Requests is a software library for C# .NET 6 that enables handling of requests in a parallel asynchronous state as Request objects. The library utilizes a priority channel to efficiently and systematically handle requests. The priority channel ensures that high-priority requests are processed before low-priority requests. This library is versatile and can be used for HTTP requests or other CPU-intensive tasks such as directory searching.
It has been specifically designed to be flexible and customizable, allowing developers to tailor the library to their specific needs. Requests is an efficient and organized solution that simplifies the process of handling requests in C# .NET 6-based applications.
Installation
You can install Requests by searching for "Requests" in the NuGet Package Manager.
Usage
To use Requests, first import the library:
using Shard.Requests;
Then, create a Request object and it will automaticly be added to the RequestHandler
.
If a request fails, the RequestHandler will automatically retry the request according to the retry settings specified.
Classes
This library includes the following classes:
- Request: Main abstract class that can be used to expand functionality on a class-based level.
- All subclasses have a retry function βΎοΈ
- A priority function π
- Delegates to notify when a
Request
started, failed, completed, or canceled π’ - Implementation for custom
CancellationToken
and a mainCancellationTokenSource
to cancel the request.
- OwnRequest: Wrapper around your own request. It is an easy-to-expand class for handling the requests without the creation of a specific class.
- RequestContainer: A container class to merge requests together and to start, pause, and await them.
- ProgressableContainer: A container class to merge requests together that are using a
Progress
object to report the progress. - RequestHandler: A class to handle requests. Every handler is independent of any other handler.
Expand and use as you like!
Examples
Here is an example of creating a child class of Request
, called OwnRequest
:
public class OwnRequest : Request<RequestOptions<VoidStruct, VoidStruct>, VoidStruct, VoidStruct>
{
private readonly Func<CancellationToken, Task<bool>> _own;
public OwnRequest(Func<CancellationToken, Task<bool>> own, RequestOptions<VoidStruct, VoidStruct>? requestOptions = null) : base(requestOptions)
{
_own = own;
AutoStart();
}
protected override async Task<RequestReturn> RunRequestAsync()
{
return new RequestReturn() { Successful = await _own.Invoke(Token) };
}
}
To create an OwnRequest
, use the following code:
// Create an object and pass as a parameter an action that uses a CancellationToken
new OwnRequest(async (token) =>
{
using HttpClient client = new();
// Create your request message. Here the body of google.com
HttpRequestMessage requestMessage = new(HttpMethod.Get, "https://www.google.com");
// Send your request and get the result. Pass the CancellationToken for handling it later over the Request object
HttpResponseMessage response = await client.SendAsync(requestMessage, token);
// If the response does not succeed
if (!response.IsSuccessStatusCode)
return false; // Return false to retry and call the failed method
// If the response succeeds. Do what you want and return to finish the request
Console.WriteLine("Finished");
return true;
});
Contributing
If you would like to contribute to this library, please submit a pull request or open an issue. We welcome all contributions and appreciate your help in making Requests the best library it can be!
License
Requests is licensed under the MIT license.
Product | Versions 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 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 was computed. 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. |
-
net6.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Shard.Requests:
Package | Downloads |
---|---|
Shard.DownloadAssistant
A free to use library as a download manager. Includes retry, priority, cancel, etc.. function. Features: β’ StatusRequest: Calls a Head request and returns a response message with the headers. β’ SiteRequest: Scans a website for all references. β’ GetRequest: To download the response into a file. β’ LoadRequest: Extends GetRequest with chunked download. |
|
Shard.WebsiteScraper
WebsiteScraper is a powerful tool that allows you to effortlessly download your favorite comics and manga from various websites. You can easily provide a JSON file containing the website links, and the scraper will do the rest. Using the advanced parsing capabilities of Angelsharp and Regex, the tool efficiently extracts the desired content from the website and saves it onto your device for offline reading. With WebsiteScraper, you can enjoy your favorite comics and manga anytime, anywhere, without any hassle. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.6 | 109 | 11/5/2024 |
2.1.5 | 96 | 10/30/2024 |
2.1.4 | 254 | 5/5/2024 |
2.1.3 | 119 | 5/5/2024 |
2.1.2 | 118 | 5/5/2024 |
2.1.1 | 116 | 5/4/2024 |
2.1.0 | 112 | 4/26/2024 |
2.0.3 | 309 | 12/14/2023 |
2.0.1 | 175 | 11/20/2023 |
2.0.0 | 216 | 10/21/2023 |
1.0.1 | 155 | 9/9/2023 |
1.0.0 | 146 | 9/8/2023 |
0.1.1 | 188 | 7/10/2023 |
0.1.0 | 155 | 6/22/2023 |