fusillade 2.6.1
Prefix ReservedSee the version list below for details.
dotnet add package fusillade --version 2.6.1
NuGet\Install-Package fusillade -Version 2.6.1
<PackageReference Include="fusillade" Version="2.6.1" />
paket add fusillade --version 2.6.1
#r "nuget: fusillade, 2.6.1"
// Install fusillade as a Cake Addin #addin nuget:?package=fusillade&version=2.6.1 // Install fusillade as a Cake Tool #tool nuget:?package=fusillade&version=2.6.1
<br /> <a href="https://github.com/reactiveui/fusillade"> <img width="120" heigth="120" src="https://raw.githubusercontent.com/reactiveui/styleguide/master/logo_fusillade/main.png"> </a>
Fusillade: An opinionated HTTP library for Mobile Development
Fusillade helps you to write more efficient code in mobile and desktop applications written in C#. Its design goals and feature set are inspired by Volley as well as Picasso.
What even does this do for me?
Fusillade is a set of HttpMessageHandlers (i.e. "drivers" for HttpClient) that make your mobile applications more efficient and responsive:
Auto-deduplication of relevant requests - if every instance of your TweetView class requests the same avatar image, Fusillade will only do one request and give the result to every instance. All
GET
,HEAD
, andOPTIONS
requests are deduplicated.Request Limiting - Requests are always dispatched 4 at a time (the Volley default) - issue lots of requests without overwhelming the network connection.
Request Prioritization - background requests should run at a lower priority than requests initiated by the user, but actually implementing this is quite difficult. With a few changes to your app, you can hint to Fusillade which requests should skip to the front of the queue.
Speculative requests - On page load, many apps will try to speculatively cache data (i.e. try to pre-download data that the user might click on). Marking requests as speculative will allow requests until a certain data limit is reached, then cancel future requests (i.e. "Keep downloading data in the background until we've got 5MB of cached data")
How do I use it?
The easiest way to interact with Fusillade is via a class called NetCache
,
which has a number of built-in scenarios:
public static class NetCache
{
// Use to fetch data into a cache when a page loads. Expect that
// these requests will only get so far then give up and start failing
public static HttpMessageHandler Speculative { get; set; }
// Use for network requests that are running in the background
public static HttpMessageHandler Background { get; set; }
// Use for network requests that are fetching data that the user is
// waiting on *right now*
public static HttpMessageHandler UserInitiated { get; set; }
}
To use them, just create an HttpClient
with the given handler:
var client = new HttpClient(NetCache.UserInitiated);
var response = await client.GetAsync("http://httpbin.org/get");
var str = await response.Content.ReadAsStringAsync();
Console.WriteLine(str);
Where does it work?
Everywhere! Fusillade is a Portable Library, it works on:
- Xamarin.Android
- Xamarin.iOS
- Xamarin.Mac
- Windows Desktop apps
- WinRT / Windows Phone 8.1 apps
- Windows Phone 8
More on speculative requests
Generally, on a mobile app, you'll want to reset the Speculative limit every time the app resumes from standby. How you do this depends on the platform, but in that callback, you need to call:
NetCache.Speculative.ResetLimit(1048576 * 5/*MB*/);
Offline Support
Fusillade can optionally cache responses that it sees, then play them back to you when your app is offline (or you just want to speed up your app by fetching cached data). Here's how to set it up:
- Implement the IRequestCache interface:
public interface IRequestCache
{
/// <summary>
/// Implement this method by saving the Body of the response. The
/// response is already downloaded as a ByteArrayContent so you don't
/// have to worry about consuming the stream.
/// <param name="request">The originating request.</param>
/// <param name="response">The response whose body you should save.</param>
/// <param name="key">A unique key used to identify the request details.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Completion.</returns>
Task Save(HttpRequestMessage request, HttpResponseMessage response, string key, CancellationToken ct);
/// <summary>
/// Implement this by loading the Body of the given request / key.
/// </summary>
/// <param name="request">The originating request.</param>
/// <param name="key">A unique key used to identify the request details,
/// that was given in Save().</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>The Body of the given request, or null if the search
/// completed successfully but the response was not found.</returns>
Task<byte[]> Fetch(HttpRequestMessage request, string key, CancellationToken ct);
}
- Set an instance to
NetCache.RequestCache
, and make some requests:
NetCache.RequestCache = new MyCoolCache();
var client = new HttpClient(NetCache.UserInitiated);
await client.GetStringAsync("https://httpbin.org/get");
- Now you can use
NetCache.Offline
to get data even when the Internet is disconnected:
// This will never actually make an HTTP request, it will either succeed via
// reading from MyCoolCache, or return an HttpResponseMessage with a 503 Status code.
var client = new HttpClient(NetCache.Offline);
await client.GetStringAsync("https://httpbin.org/get");
How do I use this with ModernHttpClient?
Add this line to a static constructor of your app's startup class:
using Splat;
Locator.CurrentMutable.RegisterConstant(new NativeMessageHandler(), typeof(HttpMessageHandler));
What do the priorities mean?
The precedence is UserInitiated > Background > Speculative Which means that anything set as UserInitiate has a higher priority than Background or Speculative.
Explicit is a special that allows to set an explicit value that can be higher, lower or in between any of the predefined cases.
var lowerThanSpeculative = new RateLimitedHttpMessageHandler(
new HttpClientHandler(),
Priority.Explicit,
9);
var moreThanSpeculativeButLessThanBAckground = new RateLimitedHttpMessageHandler(
new HttpClientHandler(),
Priority.Explicit,
15);
var doItBeforeEverythingElse = new RateLimitedHttpMessageHandler(
new HttpClientHandler(),
Priority.Explicit,
1000);
Statics? That sucks! I like $OTHER_THING! Your priorities suck, I want to come up with my own scheme!
NetCache
is just a nice pre-canned default, the interesting code is in a
class called RateLimitedHttpMessageHandler
. You can create it explicitly and
configure it as-needed.
What's with the name?
The word 'Fusillade' is a synonym for Volley 😃
Contribute
Fusillade is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use. Because of our Open Collective model for funding and transparency, we are able to funnel support and funds through to our contributors and community. We ❤ the people who are involved in this project, and we’d love to have you on board, especially if you are just getting started or have never contributed to open-source before.
So here's to you, lovely person who wants to join us — this is how you can support us:
- Responding to questions on StackOverflow
- Passing on knowledge and teaching the next generation of developers
- Donations and Corporate Sponsorships
- Asking your employer to reciprocate and contribute to open-source
- Submitting documentation updates where you see fit or lacking.
- Making contributions to the code base.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- punchclock (>= 3.4.3)
- Splat (>= 14.7.1)
- System.Net.Http (>= 4.3.4)
- System.Reactive (>= 6.0.0)
-
net6.0
- punchclock (>= 3.4.3)
- Splat (>= 14.7.1)
- System.Net.Http (>= 4.3.4)
- System.Reactive (>= 6.0.0)
-
net7.0
- punchclock (>= 3.4.3)
- Splat (>= 14.7.1)
- System.Net.Http (>= 4.3.4)
- System.Reactive (>= 6.0.0)
NuGet packages (14)
Showing the top 5 NuGet packages that depend on fusillade:
Package | Downloads |
---|---|
ModSink.Common
This library contains most of the logic for ModSink. |
|
XamBasePacket
Includes all needed classes models and libs to start developing Xamarin application. |
|
BD.Common.Mvvm
次元超越 Mvvm 库 |
|
Xablu.WebApiClient
The Xablu WebApiClient is a C# HTTP library which aims to simplify consuming of Web API services in .NET projects. |
|
TranquilHTTP
Tranquil HTTP is a C# HTTP library for Mobile Development aiming to make it really easy to solve complex HTTP communication scenarios. |
GitHub repositories (4)
Showing the top 4 popular GitHub repositories that depend on fusillade:
Repository | Stars |
---|---|
BeyondDimension/SteamTools
🛠「Watt Toolkit」是一个开源跨平台的多功能 Steam 工具箱。
|
|
reactiveui/ReactiveUI.Samples
This repository contains ReactiveUI samples.
|
|
HTBox/crisischeckin
Crisischeckin Humanitarian Toolbox repository
|
|
Respawnsive/Apizr
Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority, etc...)
|
Version | Downloads | Last updated |
---|---|---|
2.6.30 | 2,782 | 5/2/2024 |
2.6.1 | 8,471 | 9/21/2023 |
2.4.67 | 19,859 | 2/1/2023 |
2.4.62 | 2,676 | 11/24/2022 |
2.4.47 | 3,882 | 6/22/2022 |
2.4.1 | 13,006 | 12/13/2021 |
2.3.1 | 32,294 | 1/22/2021 |
2.2.9 | 2,778 | 11/27/2020 |
2.2.1 | 2,480 | 10/23/2020 |
2.1.9 | 12,710 | 7/29/2020 |
2.1.1 | 27,725 | 5/10/2020 |
2.0.5 | 98,996 | 4/2/2019 |
2.0.2 | 3,759 | 2/19/2019 |
2.0.1 | 5,561 | 2/5/2019 |
1.0.0 | 52,053 | 9/5/2017 |
0.7.0 | 43,767 | 11/10/2016 |
0.6.0 | 96,699 | 5/1/2014 |
0.5.0 | 1,680 | 4/25/2014 |