Phetch.Core
1.0.0
dotnet add package Phetch.Core --version 1.0.0
NuGet\Install-Package Phetch.Core -Version 1.0.0
<PackageReference Include="Phetch.Core" Version="1.0.0" />
paket add Phetch.Core --version 1.0.0
#r "nuget: Phetch.Core, 1.0.0"
// Install Phetch.Core as a Cake Addin #addin nuget:?package=Phetch.Core&version=1.0.0 // Install Phetch.Core as a Cake Tool #tool nuget:?package=Phetch.Core&version=1.0.0
Phetch
Documentation | API Reference | Sample app
Phetch is a small Blazor library for handling async query state, in the style of React Query, SWR, or RTK Query.
Currently, Phetch is only designed for use with Blazor WebAssembly. However, the core package (Phetch.Core) has no dependencies on Blazor or ASP.NET Core, so in theory it can be used anywhere that supports .NET Standard 2.1.
Features
- Automatically handles loading and error states, and updates your components whenever the state changes.
- Automatically caches data returned by queries, and makes it easy to invalidate or update this cached data when needed.
- Supports calling any async method as a query (not restricted just to HTTP requests).
- Supports pagination, prefetching, request de-duplication, retries, dependent queries, CancellationTokens, and more.
- 100% strongly typed, with nullability annotations.
- Lightweight and easy to combine with other state management methods.
- No Javascript needed!
Show me some code!
Click here to view the source code for the sample project, with more detailed examples.
Below is the code for a basic component that runs a query when the component is first loaded. Phetch can do a whole lot more than that though, so make sure to check out the samples project and full documentation!
Defining an endpoint:
using Phetch.Core;
// This defines an endpoint that takes an int and returns a bool.
var isEvenEndpoint = new Endpoint<int, bool>(
// Replace this part with your own async function:
async (value, cancellationToken) =>
{
var response = await httpClient.GetFromJsonAsync<dynamic>(
$"https://api.isevenapi.xyz/api/iseven/{value}",
cancellationToken);
return response.IsEven;
}
);
Using the endpoint in a component:
@using Phetch.Blazor
<UseEndpoint Endpoint="isEvenEndpoint" Arg="3" Context="query">
@if (query.IsError) {
<p>Something went wrong!</p>
} else if (query.IsLoading) {
<p>Loading...</p>
} else if (query.HasData) {
<p>The number is @(query.Data ? "even" : "odd")</p>
}
</UseEndpoint>
<details> <summary>Some notes on the example above</summary>
- Inside the
<UseEndpoint>
component, you can usequery
to access the current state of the query. Changing theContext
parameter will rename this object. - By changing the
Arg
parameter, the query will automatically be re-fetched when needed. - Normally, you would share endpoints around your application using dependency injection (see Defining Query Endpoints).
- If you need to access the query state inside the
@code
block of a component, you can replace<UseEndpoint/>
with the pattern described in Using Query Objects Directly.
</details> </br>
Click here to go to the full documentation
Installing
You can install Phetch via the .NET CLI with the following command:
dotnet add package Phetch.Blazor
If you're using Visual Studio, you can also install via the built-in NuGet package manager.
Contributing
Any contributions are welcome, but ideally start by creating an issue.
Comparison with other libraries
- Fluxor, Blazor-State or Cortex.Net: These are general-purpose state management libraries, so:
- They will give you more control over exactly how your state is updated, and will work for managing non-query state.
- However, for managing query state, you will need much more code to achieve the same things that Phetch can do in just a couple of lines. This becomes particularly important if you need to cache data or share queries across components.
- Fusion: This is a much larger library, focused on real-time updates. Fusion is great if your app has lots of real-time functionality, but for most applications it will probably be overkill compared to Phetch.
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 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 | 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
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Phetch.Core:
Package | Downloads |
---|---|
Phetch.Blazor
A small Blazor library for handling async query state, in the style of React Query |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 686 | 7/13/2024 |
0.7.1 | 1,671 | 6/8/2024 |
0.7.0 | 665 | 5/4/2024 |
0.6.0 | 722 | 12/1/2023 |
0.5.1 | 353 | 7/14/2023 |
0.5.0 | 225 | 6/19/2023 |
0.4.0 | 342 | 3/6/2023 |
0.3.1 | 442 | 11/19/2022 |
0.3.0 | 445 | 11/13/2022 |
0.2.0 | 542 | 8/18/2022 |
0.1.2 | 550 | 8/6/2022 |
0.1.1 | 545 | 8/1/2022 |
0.1.0 | 553 | 7/26/2022 |
0.0.3 | 581 | 7/9/2022 |