{"id":16333163,"url":"https://github.com/brianmcgee/nats-http","last_synced_at":"2025-09-24T00:45:23.766Z","repository":{"id":176919010,"uuid":"659729152","full_name":"brianmcgee/nats-http","owner":"brianmcgee","description":"A HTTP Transport for NATS","archived":false,"fork":false,"pushed_at":"2023-07-03T19:53:57.000Z","size":68,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-29T08:38:46.681Z","etag":null,"topics":["go","golang","http","nats"],"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/brianmcgee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-06-28T12:41:02.000Z","updated_at":"2025-02-26T13:02:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa5f0e7c-389f-4df7-90ea-11cd38189371","html_url":"https://github.com/brianmcgee/nats-http","commit_stats":null,"previous_names":["brianmcgee/nats.http"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brianmcgee/nats-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianmcgee%2Fnats-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianmcgee%2Fnats-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianmcgee%2Fnats-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianmcgee%2Fnats-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brianmcgee","download_url":"https://codeload.github.com/brianmcgee/nats-http/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianmcgee%2Fnats-http/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276673796,"owners_count":25683943,"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","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang","http","nats"],"created_at":"2024-10-10T23:34:32.765Z","updated_at":"2025-09-24T00:45:23.746Z","avatar_url":"https://github.com/brianmcgee.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e \n  \u003cbr\u003e\n  nats-http\n  \u003cbr\u003e \n\u003c/h1\u003e\n\n![Build](https://github.com/brianmcgee/nats-http/actions/workflows/ci.yaml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/brianmcgee/nats-http/badge.svg)](https://coveralls.io/github/brianmcgee/nats-http)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n**Status: experimental**\n\n# Usage\n\nThe project is currently in a state of rapid iteration. I will update this section and add more documentation as features\nmature and reach a steady state.\n\n## Client\n\n```go\n// connect to NATS\nconn, err := nats.Connect(nats.DefaultURL)\nif err != nil {\n    panic(err)\n}\n\n// create a client using the nats transport\nclient := http.Client{\n    Transport: \u0026Transport{\n        Conn: conn,\n    },\n}\n\n// perform a get request against a NATS Http Server configured to listen on the 'foo.bar.\u003e' subject hierarchy\n// it's important to use the 'nats+http' url scheme\n\nresp, err := client.Get(\"nats+http://foo.bar/hello/world\")\nif err != nil {\n    panic(err)\n}\n\nbody, err := io.ReadAll(resp.Body)\nif err != nil {\n    panic(err)\n}\n\nprintln(string(body))\n```\n\n## Server\n\n```go\n// connect to NATS\nconn, err := nats.Connect(nats.DefaultURL)\nif err != nil {\n    panic(err)\n}\n\n// create a router\nrouter := chi.NewRouter()\nrouter.Head(\"/hello\", func(w http.ResponseWriter, r *http.Request) {\n    _, _ = io.WriteString(w, \"world\")\n})\n\n// create a server\nsrv := Server{\n    Conn:    conn,\n    Subject: \"foo.bar\",   // it will listen for requests on the 'foo.bar.\u003e' subject hierarchy\n    Group:   \"my-server\", // name of the queue group when subscribing, used for load balancing\n    Handler: router,\n}\n\n// create a context and an error group for running processes\nctx, cancel := context.WithCancel(context.Background())\neg := errgroup.Group{}\n\n// start listening\neg.Go(func() error {\n    return srv.Listen(ctx)\n})\n\n// wait 10 seconds then cancel the context\neg.Go(func() error {\n    \u003c-time.After(10 * time.Second)\n    cancel()\n    return nil\n})\n\n// wait for the listener to complete\nif err = eg.Wait(); err != nil {\n    panic(err)\n}\n```\n\n## Proxy\n\n```go\n// connect to NATS\nconn, err := nats.Connect(nats.DefaultURL)\nif err != nil {\n    panic(err)\n}\n\n// create a TCP listener\nlistener, err := net.Listen(\"tcp\", \"localhost:8080\")\nif err != nil {\n    panic(err)\n}\n\n// create a proxy which forwards requests to 'test.service.\u003e' subject hierarchy\nproxy := Proxy{\n    Subject: \"test.service\",\n    Listener: listener,\n    Transport: \u0026Transport{\n        Conn: conn,\n    },\n}\n\n// create a context and an error group for running processes\nctx, cancel := context.WithCancel(context.Background())\neg := errgroup.Group{}\n\n// start listening\neg.Go(func () error {\n    return proxy.Listen(ctx)\n})\n\n// wait 10 seconds then cancel the context\neg.Go(func () error {\n    \u003c-time.After(10 * time.Second)\n    cancel()\n    return nil\n})\n\n// wait for the listener to complete\nif err = eg.Wait(); err != nil {\n    panic(err)\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianmcgee%2Fnats-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianmcgee%2Fnats-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianmcgee%2Fnats-http/lists"}