{"id":32663937,"url":"https://github.com/jdtoon/swap","last_synced_at":"2026-03-04T09:00:53.865Z","repository":{"id":321036492,"uuid":"1084211087","full_name":"jdtoon/swap","owner":"jdtoon","description":"HTMX + .NET library","archived":false,"fork":false,"pushed_at":"2026-01-19T12:04:09.000Z","size":27689,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2026-01-26T09:59:07.085Z","etag":null,"topics":["aspnetcore","csharp","dotnet","htmx"],"latest_commit_sha":null,"homepage":"https://swaphtmx.dev/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdtoon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-27T11:28:47.000Z","updated_at":"2026-01-19T12:03:42.000Z","dependencies_parsed_at":"2025-10-27T13:25:56.220Z","dependency_job_id":null,"html_url":"https://github.com/jdtoon/swap","commit_stats":null,"previous_names":["jdtoon/swap"],"tags_count":41,"template":false,"template_full_name":null,"purl":"pkg:github/jdtoon/swap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdtoon%2Fswap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdtoon%2Fswap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdtoon%2Fswap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdtoon%2Fswap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdtoon","download_url":"https://codeload.github.com/jdtoon/swap/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdtoon%2Fswap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30076935,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T08:01:56.766Z","status":"ssl_error","status_checked_at":"2026-03-04T08:00:42.919Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","csharp","dotnet","htmx"],"created_at":"2025-10-31T23:01:02.314Z","updated_at":"2026-03-04T09:00:53.858Z","avatar_url":"https://github.com/jdtoon.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swap.Htmx\n\n**Server-driven web apps, made simple.**\n\n[![NuGet](https://img.shields.io/nuget/v/Swap.Htmx.svg)](https://www.nuget.org/packages/Swap.Htmx)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n---\n\nBuild interactive web applications with server-rendered HTML. Keep JavaScript focused on interactions, not state management. No build tools.\n\n**One event. Multiple UI updates. Zero client-side state.**\n\n### The Code\n\n```csharp\n// 1. Controller: Return a SwapView\npublic IActionResult Index() =\u003e SwapView(new TaskModel());\n\n// 2. Action: Perform logic, return updates\n[HttpPost]\npublic IActionResult Complete(int id)\n{\n    _tasks.Complete(id);\n    \n    // Updates the \"task-list\" element with the \"_TaskList\" partial\n    return this.SwapResponse()\n        .WithView(\"_TaskList\", _tasks.GetAll()) \n        .WithSuccessToast(\"Task completed!\")\n        .Build();\n}\n```\n\n```html\n\u003c!-- 3. View (_TaskList.cshtml): Standard Razor, no JS logic --\u003e\n\u003cdiv id=\"task-list\"\u003e\n    @foreach (var task in Model) {\n        \u003cdiv class=\"task @(task.IsComplete ? \"done\" : \"\")\"\u003e\n             @task.Title\n        \u003c/div\u003e\n    }\n\u003c/div\u003e\n```\n\n---\n\n## Quick Start\n\n### 1. New Project (Recommended)\n\n```bash\ndotnet new install Swap.Templates\ndotnet new swap-minimal -n MyApp\ncd MyApp\ndotnet run\n```\n\n### 2. Existing Project\n\n```bash\ndotnet add package Swap.Htmx\n```\n\n```csharp\n// Program.cs\nbuilder.Services.AddControllersWithViews();\nbuilder.Services.AddSwapHtmx(); // \u003c-- Add this\n\nvar app = builder.Build();\napp.UseStaticFiles();\napp.UseRouting();\napp.UseSwapHtmx(); // \u003c-- Add this\napp.MapControllers();\napp.Run();\n```\n\n---\n\n## Core Concepts\n\n### 1. Smart Views (`SwapView`)\n\nDon't worry about \"full page vs partial\". `SwapView` handles it.\n\n```csharp\n// Browser request -\u003e Returns View(\"Index\", model) (Full Page)\n// HTMX request    -\u003e Returns PartialView(\"Index\", model) (Content Only)\nreturn SwapView(model);\n```\n\n### 2. Smart State (`SwapState`)\n\nForget hidden inputs. Use a strong-typed state class.\n\n```csharp\npublic class FilterState : SwapState \n{ \n    public string Search { get; set; }\n    public int Page { get; set; } = 1; \n}\n```\n\n```html\n\u003c!-- Renders all hidden fields automatically --\u003e\n\u003cswap-state state=\"Model.State\" /\u003e\n\n\u003c!-- Binds automatically in controller --\u003e\n\u003cinput type=\"text\" name=\"Search\" hx-get=\"...\" hx-include=\"#filter-state\" /\u003e\n```\n\n### 3. Smart Events (`SwapEvent`)\n\nDecouple your UI updates. One action can trigger multiple independent components to refresh.\n\n```csharp\n// Controller just says \"Something happened\"\nreturn SwapEvent(\"task.completed\", id).Build();\n\n// Handler updates the stats panel\n[SwapHandler]\npublic class StatsHandler : ISwapEventHandler\n{\n    public Task HandleAsync(...) =\u003e builder.AlsoUpdate(\"stats\", \"_Stats\", model);\n}\n```\n\n---\n\n## Advanced Features\n\n### Source Generators (No Magic Strings)\nSwap automatically generates constants for your Views and Element IDs.\n\n```csharp\n// Instead of \"stats-panel\" and \"_Stats\"\nbuilder.AlsoUpdate(SwapElements.StatsPanel, SwapViews.Home._Stats, model);\n```\n\n### Tamper-Proof State\nEncrypt sensitive state values in the browser automatically.\n\n```csharp\npublic class PaymentState : SwapState\n{\n    public override bool Protected =\u003e true; // Encrypts all properties\n    public decimal Amount { get; set; }\n}\n```\n\n### SwapStories (Component Playground)\nDevelop and test partials in isolation.\n\n```csharp\n[SwapStory(\"Product Card\", \"Components\")]\npublic IActionResult Card() =\u003e PartialView(\"_ProductCard\", new Product(...));\n```\n\n### Realtime (SSE)\nUpdate clients in real-time without complex WebSocket setup.\n\n```csharp\n// Broadcast an update to all connected clients\nawait _publisher.Publish(\"task.completed\", id);\n```\n\n### Performance \u0026 Security\nOOB swaps render in parallel — dashboards with 12+ partials update fast. Target IDs are validated against injection attacks, and redirect URLs reject dangerous schemes (`javascript:`, `data:`, `vbscript:`).\n\n---\n\n## Documentation \u0026 Demos\n- **[Documentation](lib/Swap.Htmx/docs)**\n  - [Getting Started](lib/Swap.Htmx/docs/GettingStarted.md)\n- **[SwapStateDemo](demo/SwapStateDemo)** - Secure state \u0026 form handling\n- **[SwapShop](demo/SwapShop)** - Full E-commerce reference app\n- **[SwapDashboard](demo/SwapDashboard)** - Complex multi-component state\n- **[SwapDebtors](demo/SwapDebtors)** - Minimal API CRUD example\n- **[SwapLab](demo/SwapLab)** - Gallery of 15+ UI patterns\n\n## License\n\nMIT — [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdtoon%2Fswap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdtoon%2Fswap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdtoon%2Fswap/lists"}