Shard.Requests
2.1.4
dotnet add package Shard.Requests --version 2.1.4
NuGet\Install-Package Shard.Requests -Version 2.1.4
<PackageReference Include="Shard.Requests" Version="2.1.4" />
paket add Shard.Requests --version 2.1.4
#r "nuget: Shard.Requests, 2.1.4"
// Install Shard.Requests as a Cake Addin #addin nuget:?package=Shard.Requests&version=2.1.4 // Install Shard.Requests as a Cake Tool #tool nuget:?package=Shard.Requests&version=2.1.4
Requests
🌟 What Is Requests?
Requests is library for C# .NET 6; it's your trusty sidekick in the world of handling requests. Imagine a friendly companion that takes care of your requests, ensuring they're processed efficiently and systematically. Whether you're dealing with HTTP requests or tackling CPU-intensive tasks like directory searching.
🚀 Why Choose Requests?
- Priority Magic: Our priority channel ensures that high-priority requests get the VIP treatment—they're processed before the rest. No more waiting in line!
- Flexibility at Its Best: Requests is designed to be as flexible as possible. Customize it to fit your specific needs, whatever you're building.
- Parallel Asynchronous Awesomeness: Handle requests in parallel, like a symphony of asynchronous harmony. 🎶
📦 Installation
Getting started with Requests is a breeze:
- Open your NuGet Package Manager.
- Search for "Shard.Requests"
- Install it. Voilà! 🎉
Usage
To utilize the Requests library in C#, begin by importing it:
using Shard.Requests;
Next, instantiate a Request
object, and it will automatically be included in the RequestHandler
. If a request encounters an error, the RequestHandler
will automatically retry the request based on the specified retry settings.
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!
Because handling requests should be as delightful as a warm cup of cocoa on a winter day.
For additional information, refer to the Requests Wiki.
Examples
Meet our star, the OwnRequest
class:
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) };
}
}
OwnRequest is a straightforward implementation of a child class of Request. It doesn’t overwhelm you with complexity, but it’s incredibly useful for quick implementations:
// 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;
});
Create your own requests with a sprinkle of magic! ✨
🌟 Contributing
Join our quest! If you'd like to contribute to this library, submit a pull request or open an issue. We appreciate your help in making Requests
the best it can be!
📜 License
Requests is licensed under the MIT license.
Free Code and Free to Use
Have fun!
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 (1)
Showing the top 1 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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Request Dispose Task not finished Fix