FSH.OfflineSync 1.0.0

dotnet add package FSH.OfflineSync --version 1.0.0
                    
NuGet\Install-Package FSH.OfflineSync -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSH.OfflineSync" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FSH.OfflineSync" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FSH.OfflineSync" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FSH.OfflineSync --version 1.0.0
                    
#r "nuget: FSH.OfflineSync, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FSH.OfflineSync@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FSH.OfflineSync&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FSH.OfflineSync&version=1.0.0
                    
Install as a Cake Tool

FSH.OfflineSync

NuGet Downloads

πŸ”„ A plug-and-play offline sync library for Blazor WebAssembly + FullStackHero apps using HttpClient, DelegatingHandler, and Blazor.Localstorage.


✨ Features

  • πŸ“‘ Caches GET API responses locally
  • πŸ“΄ Queues POST/PUT/DELETE requests offline
  • πŸ” Automatically syncs when connection is restored
  • πŸ” Attaches Authorization: Bearer <token> using Blazored.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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