{"id":21331562,"url":"https://github.com/lukechampine/httprpc","last_synced_at":"2025-07-12T10:30:50.637Z","repository":{"id":57510383,"uuid":"124836951","full_name":"lukechampine/httprpc","owner":"lukechampine","description":"An HTTP wrapper for net/rpc","archived":false,"fork":false,"pushed_at":"2018-03-12T18:15:15.000Z","size":9,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T11:13:27.624Z","etag":null,"topics":["http","json-rpc","rpc"],"latest_commit_sha":null,"homepage":null,"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/lukechampine.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}},"created_at":"2018-03-12T05:16:16.000Z","updated_at":"2024-06-20T11:13:27.625Z","dependencies_parsed_at":"2022-09-26T17:50:55.187Z","dependency_job_id":null,"html_url":"https://github.com/lukechampine/httprpc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechampine%2Fhttprpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechampine%2Fhttprpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechampine%2Fhttprpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechampine%2Fhttprpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukechampine","download_url":"https://codeload.github.com/lukechampine/httprpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225814912,"owners_count":17528295,"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":["http","json-rpc","rpc"],"created_at":"2024-11-21T22:42:25.304Z","updated_at":"2024-11-21T22:42:25.981Z","avatar_url":"https://github.com/lukechampine.png","language":"Go","readme":"httprpc\n=======\n\n[![GoDoc](https://godoc.org/github.com/lukechampine/httprpc?status.svg)](https://godoc.org/github.com/lukechampine/httprpc)\n[![Go Report Card](http://goreportcard.com/badge/github.com/lukechampine/httprpc)](https://goreportcard.com/report/github.com/lukechampine/httprpc)\n\n```\ngo get github.com/lukechampine/httprpc\n```\n\n`httprpc` provides HTTP wrappers for the `net/rpc` package.\n\nWhile the `net/rpc` package does provide `DialHTTP` and `ServeHTTP` functions,\nthese only support Go's `gob` encoding format, and do so by hijacking the\nunderlying HTTP connection. `httprpc` supports any text-based format\nsatisfying the `rpc.ServerCodec`/`rpc.ClientCodec` interfaces (most notably\nJSON-RPC) by storing request/response payloads in the request/response body.\n\n`httprpc` has only been tested with JSON-RPC.\n\nUsage\n-----\n\n```go\ntype Args struct {\n\tA, B int\n}\n\ntype Arith int\n\nfunc (t *Arith) Multiply(args *Args, reply *int) error {\n\t*reply = args.A * args.B\n\treturn nil\n}\n\nfunc jsonBasicAuthHandler(next http.Handler, password string) http.HandlerFunc {\n\treturn func(w http.ResponseWriter, req *http.Request) {\n\t\t_, pass, ok := req.BasicAuth()\n\t\tif !ok || pass != password {\n\t\t\tw.Header().Set(\"WWW-Authenticate\", \"Basic realm=\\\"MyRealm\\\"\")\n\t\t\thttp.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)\n\t\t\treturn\n\t\t}\n\t\tif req.Header.Get(\"Content-Type\") != \"application/json\" {\n\t\t\thttp.Error(w, http.StatusText(http.StatusUnsupportedMediaType), http.StatusUnsupportedMediaType)\n\t\t\treturn\n\t\t}\n\n\t\tw.Header().Set(\"Content-Type\", \"application/json\")\n\t\tnext.ServeHTTP(w, req)\n\t}\n}\n\nfunc main() {\n\t// create JSON-RPC HTTP server, wrapped with Basic Auth middleware\n\trpc.Register(new(Arith))\n\tsrv := httprpc.NewServer(rpc.DefaultServer, jsonrpc.NewServerCodec)\n\tsrv = jsonBasicAuthHandler(srv, \"foo\")\n\tgo http.ListenAndServe(\":5555\", srv)\n\n\t// create JSON-RPC HTTP client, wrapped with Basic Auth \"tweak\"\n\tc := httprpc.NewClient(\"http://127.0.0.1:5555\", jsonrpc.NewClientCodec, func(req *http.Request) {\n\t\treq.SetBasicAuth(\"\", \"foo\")\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t})\n\n\t// invoke RPC\n\targs := \u0026Args{7, 8}\n\tvar reply int\n\terr := c.Call(\"Arith.Multiply\", args, \u0026reply)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Printf(\"Arith: %d*%d=%d\\n\", args.A, args.B, reply)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechampine%2Fhttprpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukechampine%2Fhttprpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechampine%2Fhttprpc/lists"}