{"id":19666865,"url":"https://github.com/mavolin/go-htmx","last_synced_at":"2025-07-09T20:32:56.508Z","repository":{"id":189788721,"uuid":"681261312","full_name":"mavolin/go-htmx","owner":"mavolin","description":"🌍️ High-level wrapper for sending and reading HTMX headers.","archived":false,"fork":false,"pushed_at":"2023-09-03T19:51:44.000Z","size":24,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-04-28T22:43:13.242Z","etag":null,"topics":["go","golang","header","headers","htmx"],"latest_commit_sha":null,"homepage":"","language":"Go","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/mavolin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2023-08-21T16:12:24.000Z","updated_at":"2025-01-18T11:41:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"47ef1cde-19bd-4c37-92ed-76e3e777fabe","html_url":"https://github.com/mavolin/go-htmx","commit_stats":null,"previous_names":["mavolin/go-htmx"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mavolin/go-htmx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavolin%2Fgo-htmx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavolin%2Fgo-htmx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavolin%2Fgo-htmx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavolin%2Fgo-htmx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mavolin","download_url":"https://codeload.github.com/mavolin/go-htmx/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mavolin%2Fgo-htmx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264502666,"owners_count":23618671,"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":["go","golang","header","headers","htmx"],"created_at":"2024-11-11T16:29:33.504Z","updated_at":"2025-07-09T20:32:56.489Z","avatar_url":"https://github.com/mavolin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003ego-htmx\u003c/h1\u003e\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/mavolin/go-htmx.svg)](https://pkg.go.dev/github.com/mavolin/go-htmx)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mavolin/corgi)](https://goreportcard.com/report/github.com/mavolin/corgi)\n[![License MIT](https://img.shields.io/github/license/mavolin/corgi)](./LICENSE)\n\u003c/div\u003e\n\n---\n\n## About\n\ngo-htmx is a helper library for setting and reading [htmx](https://htmx.org) headers.\n\n## Main Features\n\n* 🏔️ High-Level wrapper around the htmx headers\n* ✏️ Overwrite header values by calling setters multiple times\n* 📖 Fully documented—so you read the header's docs directly in your IDE\n* ✅ Proper JSON handling\n\n## Examples\n\n### 👓️ Reading Request Headers\n\nThe headers set by htmx can be retrieved by calling `htmx.Request`.\n\nIf `htmx.Request` returns nil `htmx.RequestHeaders`, the request was not made\nby htmx.\n\n```go\nfunc retrieveHeaders(r *http.Request, w http.ResponseWriter) {\n    fmt.Println(\"boosted:\", htmx.Request(r).Boosted)\n    fmt.Println(\"current url:\", htmx.Request(r).CurrentURL)\n    // you get the idea...\n}\n```\n\n### ✏️ Setting Response Headers\n\nTo add response headers, you first need to add the htmx middleware.\n\nBy using a middleware instead of setting headers directly\nyou can overwrite response headers at a later point in your code.\nThis is useful if you have a default value for a header that only changes in certain cases.\n\nIt also means you can add event triggers one by one and don't have to set them at once.\n\nFor [chi](https://github.com/go-chi/chi), adding the middleware could look like this:\n\n```go\nr := chi.NewRouter()\nr.Use(htmx.NewMiddleware())\n```\n\nThe middleware will add the headers once the first call to `http.ResponseWriter.Write` is made.\n\nAfter you've added the middleware, you can start setting headers:\n\n```go\ntype reloadNavData struct {\n\tActiveEntry string\n}\n\nfunc setHeaders(r *http.Request, w http.ResponseWriter) {\n    htmx.Retarget(r, \"#main\")\n    htmx.Trigger(r, \"reload-nav\", reloadNavData{ActiveEntry: \"foo\"})\n    htmx.Trigger(r, \"update-cart\", nil)\n\t\n    // HX-Retarget: #main \n    // HX-Trigger: {\"reload-nav\": {\"ActiveEntry\": \"foo\"}, \"update-cart\": null}\n}\n```\n\nYou can find the full list of setters on [pkg.go.dev](https://pkg.go.dev/github.com/mavolin/go-htmx).\n\n## License\n\nBuilt with ❤ by [Maximilian von Lindern](https://github.com/mavolin).\nAvailable under the [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmavolin%2Fgo-htmx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmavolin%2Fgo-htmx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmavolin%2Fgo-htmx/lists"}