FSH.OfflineSync
1.0.0
dotnet add package FSH.OfflineSync --version 1.0.0
NuGet\Install-Package FSH.OfflineSync -Version 1.0.0
<PackageReference Include="FSH.OfflineSync" Version="1.0.0" />
<PackageVersion Include="FSH.OfflineSync" Version="1.0.0" />
<PackageReference Include="FSH.OfflineSync" />
paket add FSH.OfflineSync --version 1.0.0
#r "nuget: FSH.OfflineSync, 1.0.0"
#:package FSH.OfflineSync@1.0.0
#addin nuget:?package=FSH.OfflineSync&version=1.0.0
#tool nuget:?package=FSH.OfflineSync&version=1.0.0
FSH.OfflineSync
π A plug-and-play offline sync library for Blazor WebAssembly + FullStackHero apps using
HttpClient
,DelegatingHandler
, andBlazor.Localstorage
.
β¨ Features
- π‘ Caches GET API responses locally
- π΄ Queues POST/PUT/DELETE requests offline
- π Automatically syncs when connection is restored
- π Attaches
Authorization: Bearer <token>
usingBlazored.LocalStorage
- π One-liner integration via
AddOfflineSyncHttpClient()
- β Designed for FullStackHero + Blazor WebAssembly
- πΎ Uses Blazor.Localstorage for durable offline support
π¦ Installation
dotnet add package FSH.OfflineSync
π Getting Started
1. Add the following to your Program.cs
:
builder.Services.AddOfflineSyncHttpClient(builder.Configuration, options =>
{
options.AuthTokenKey = StorageConstants.Local.AuthToken; // or "authToken" Or StorageConstants.Local.AuthToken if using FullStackHero
});
2. Add your API domain to wwwroot/appsettings.json
:
{
"APIDomain": "https://your-api-domain.com"
}
π§© Whatβs Registered Automatically
Service | Purpose |
---|---|
OfflineDelegatingHandler |
Intercepts API calls and manages caching |
AuthHeaderHandler |
Adds Authorization header from local storage |
OfflineSyncService |
Manages offline queue and sync process |
ILocalStorageService |
Handles token and local cache storage |
HttpClient ("FSHClient") |
Pre-configured with handlers and base URL |
βοΈ Configuration
public class OfflineSyncOptions
{
public string AuthTokenKey { get; set; } = "authToken";
}
If your app uses a different key for the auth token in localStorage
, pass it via OfflineSyncOptions
.
π§ Sample Usage
You don't need to change how you use HttpClient
. All GET/POST/PUT/DELETE calls will work as usual:
@inject HttpClient Http
var result = await Http.GetFromJsonAsync<List<Product>>("api/products");
If the app is offline:
GET
will return from local cache (if available)POST/PUT/DELETE
will be queued in IndexedDB and synced when online
π Project Structure
FSH.OfflineSync/
β
βββ Extensions/
β βββ ServiceCollectionExtensions.cs
β
βββ Handlers/
β βββ OfflineDelegatingHandler.cs
β βββ AuthHeaderHandler.cs
β
βββ Services/
β βββ OfflineSyncService.cs
β βββ IOfflineSyncService.cs
β
βββ Models/
β βββ QueuedRequest.cs
β βββ SyncResult.cs
β
βββ JSInterop/
β βββ OfflineSyncJsInterop.cs
β
βββ Options/
β βββ OfflineSyncOptions.cs
β
βββ wwwroot/
β βββ manifest.sync.json (optional)
β
βββ FSH.OfflineSync.csproj
π Roadmap / Future Enhancements
- π Background sync using Service Workers
- βοΈ Configurable retry policy (e.g., exponential backoff)
- πͺ΅ Logging support via
ILogger
- πΆ
<OfflineStatus>
UI component - π Encrypted offline storage
- π§ͺ Unit test project + integration test sample
- π§© Typed API client (
IApiClient
) - π Sample app (
ConsumerApp
) in repo - π¦ NuGet & CI/CD auto-publish
β GitHub Actions: CI/CD Workflow
π License
MIT Β© 2025 β Developed by KyrilosAdel
π¬ Support & Contributions
Feel free to open issues or submit pull requests. Contributions are welcome!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Blazored.LocalStorage (>= 4.5.0)
- Microsoft.Extensions.Http (>= 9.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 127 | 7/27/2025 |