{"id":19110016,"url":"https://github.com/zeiss/fiber-htmx","last_synced_at":"2025-07-06T04:34:37.237Z","repository":{"id":220721453,"uuid":"752387590","full_name":"ZEISS/fiber-htmx","owner":"ZEISS","description":"🔨Write HTML and HTMX applications in pure Go using ⚡️ fiber. And lot more ...","archived":false,"fork":false,"pushed_at":"2025-03-31T04:16:52.000Z","size":4905,"stargazers_count":60,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T07:04:52.793Z","etag":null,"topics":["fiber","golang","htmx","middleware"],"latest_commit_sha":null,"homepage":"","language":"CSS","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/ZEISS.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-02-03T19:29:17.000Z","updated_at":"2025-03-31T04:16:54.000Z","dependencies_parsed_at":"2024-11-06T11:26:29.091Z","dependency_job_id":"8d64c4ae-b947-4928-b851-87640ab849ea","html_url":"https://github.com/ZEISS/fiber-htmx","commit_stats":null,"previous_names":["zeiss/fiber-htmx"],"tags_count":130,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZEISS%2Ffiber-htmx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZEISS%2Ffiber-htmx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZEISS%2Ffiber-htmx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZEISS%2Ffiber-htmx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZEISS","download_url":"https://codeload.github.com/ZEISS/fiber-htmx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247615382,"owners_count":20967184,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["fiber","golang","htmx","middleware"],"created_at":"2024-11-09T04:23:17.649Z","updated_at":"2025-04-07T08:16:40.226Z","avatar_url":"https://github.com/ZEISS.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔨 HTMX\n\n[![Test \u0026 Build](https://github.com/zeiss/fiber-htmx/actions/workflows/main.yml/badge.svg)](https://github.com/zeiss/fiber-htmx/actions/workflows/main.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/zeiss/fiber-htmx.svg)](https://pkg.go.dev/github.com/zeiss/fiber-htmx)\n[![Go Report Card](https://goreportcard.com/badge/github.com/zeiss/fiber-htmx)](https://goreportcard.com/report/github.com/zeiss/fiber-htmx)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Taylor Swift](https://img.shields.io/badge/secured%20by-taylor%20swift-brightgreen.svg)](https://twitter.com/SwiftOnSecurity)\n\nA Go package to write HTML5 and HTMX components in Go. The package is designed to work with [fiber](http://gofiber.io) and [htmx](https://htmx.org/).\n\n## Features\n\n- Write declartive HTML5 components in Go without using templates and with the full-power of a type-safe language, auto-completion, and refactoring.\n- Full support for HTMX components.\n- No dependencies on JavaScript frameworks.\n- Fast rendering of HTML5 and HTMX components.\n- Easy to use and learn.\n- Easy to extend and customize.\n\n## Installation\n\n```bash\ngo get github.com/zeiss/fiber-htmx\n```\n\nThe available web components are published in the `fiber-htmx` package.\n\n```go\nhtmx.HTML5(\n    htmx.HTML5Props{\n        Head: []htmx.Node{\n            htmx.Script(\n                htmx.Src(\"https://unpkg.com/fiber-htmx@1.3.32\"),\n            ),\n            htmx.Link(\n                htmx.Rel(\"stylesheet\"),\n                htmx.Href(\"https://unpkg.com/fiber-htmx@1.3.32/dist/out.css\"),\n            ),\n        },\n    },\n    htmx.Body(\n        htmx.ClassNames{},\n        htmx.Toasts(),\n    ),\n)\n```\n\n### Example\n\nCreating a button leveraging htmx is as easy as this.\n\n```go\nhtmx.Button(\n    htmx.Attribute(\"type\", \"submit\")\n    htmx.Text(\"Button\"),\n    htmx.HxPost(\"/api/respond\")\n)\n```\n\nThere are additional complex components that help to write HTML5 and HTMX components in Go.\n\n- [x] [htmx](https://htmx.org/)\n- [x] [HTML5](https://www.w3.org/TR/2011/WD-html5-20110405/)\n- [x] [TailwindCSS](https://tailwindcss.com/)\n- [x] [Alpine.js](https://alpinejs.dev/)\n- [ ] [DaisyUI](https://daisyui.com/) (WIP)\n- [ ] [Heroicons](https://heroicons.com/) (WIP)\n\n## Elements\n\nHTML and HTMX elements are represented as functions in Go. The functions are used to create the elements.\n\n```go\nhtmx.Div(\n    htmx.ClassNames{\n        tailwind.FontSemibold: true,\n    },\n    htmx.Text(\"Hello World\"),\n)\n```\n\nThis will create the following HTML element.\n\n```html\n\u003cdiv class=\"font-semibold\"\u003eHello World\u003c/div\u003e\n```\n\nThere is support for all HTML5 elements and Tailwind classes. Use `import \"github.com/zeiss/fiber-htmx/tailwind\"` to include Tailwind classes.\n\n## Components\n\nWrite HTML5 and HTMX components in Go.\n\n```go\nfunc HelloWorld() htmx.Node {\n    return htmx.Div(\n        htmx.ClassNames{\n            \"font-semibold\",\n        },\n        htmx.Text(\"Hello World\"),\n    )\n}\n```\n\nThere are different types of composition. For example, passing children to a component.\n\n```go\nfunc HelloWorld(children ...htmx.Node) htmx.Node {\n    return htmx.Div(\n        htmx.ClassNames{\n            \"font-semibold\",\n        },\n        htmx.Text(\"Hello World\"),\n        htmx.Div(\n            htmx.ClassNames{\n                \"text-red-500\",\n            },\n            htmx.Group(children...),\n        ),\n    )\n}\n```\n\nStyling of components is done with the `htmx.ClassNames` type.\n\n```go\nfunc HelloWorld() htmx.Node {\n    return htmx.Div(\n        htmx.ClassNames{\n            tailwind.FontSemibold: true,\n            \"text-red-500\": true,\n        },\n        htmx.Text(\"Hello World\"),\n    )\n}\n```\n\nThere are also helpers to make the life with styling easier by merging classes.\n\n```go\nfunc HelloWorld(classes htmx.ClassNames) htmx.Node {\n    return htmx.Div(\n        htmx.Merge(\n            htmx.ClassNames{\n                \"font-semibold\",\n                \"text-red-500\",\n            },\n            classes,\n        )\n        htmx.Text(\"Hello World\"),\n    )\n}\n```\n\nThere is also the option to use `htmx.Controller` to encapsulate the logic of the components.\n\n```go\n\nfunc NewHelloWorldController() htmx.ControllerFactory {\n  return func() htmx.Controller {\n    return \u0026NewHelloWorldController{}\n  }\n}\n\ntype HelloWorldController struct {\n    htmx.DefaultController\n}\n\nfunc (c *HelloWorldController) Get() error {\n    return c.Render(\n      htmx.HTML5(\n            htmx.HTML5Props{\n                Title:    \"index\",\n                Language: \"en\",\n                Head: []htmx.Node{},\n            },\n            htmx.Div(\n                htmx.ClassNames{},\n                htmx.Text(\"Hello World\"),\n            ),\n        ),\n    )    \n}\n\napp := fiber.New()\napp.Get(\"/\", htmx.NewHxControllerHandler(NewHelloWorldController()))\n\napp.Listen(\":3000\")\n```\n\n## Server-side events (SSE)\n\nThe package supports server-side events (SSE) to update the components on the client-side.\n\n```go\nmanager := sse.NewBroadcastManager(5)\napp.Get(\"/sse\", sse.NewSSEHandler(manager))\n```\n## Error Handling\n\nThere are components that enable handling fallbacks in case of errors and to recover from panics in rendering components.\n\n```go\nhtmx.Fallback(\n  htmx.ErrorBoundary(\n    func() htmx.Node {\n      return utils.Panic(errors.New(\"panic\"))\n    },\n  ),\n  htmx.Text(\"Fallback\"),\n),\n```\n\n## Examples\n\nSee [examples](https://github.com/zeiss/fiber-htmx/tree/master/examples) to understand the provided interfaces.\n\n## Benchmarks\n\n```bash\nBenchmarkElement-10                     12964440                77.40 ns/op\nBenchmark_AttrRender-10                 16038232                74.15 ns/op\nBenchmark_HTML5_Render-10                   1392            847193 ns/op\nBenchmark_ClassNames_Render-10           3166761               378.2 ns/op\n```\n\nRendering `10.000` nodes took `\u003e0.8ms`. The package is fast enough to render HTML5 and HTMX components. \n\n## License\n\n[MIT](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeiss%2Ffiber-htmx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeiss%2Ffiber-htmx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeiss%2Ffiber-htmx/lists"}