sourcegraph / jsonrpc2

Package jsonrpc2 provides a client and server implementation of JSON-RPC 2.0 (http://www.jsonrpc.org/specification)
MIT License
190 stars 62 forks source link

Implement ObjectStream as a net/http Client #39

Open abourget opened 4 years ago

abourget commented 4 years ago

Any chance we could have samples of how to integrate http.Client into the flow?

The lib is nice and clean, but not easy to get started with a simple use case of hitting an HTTP server. Requiring TCP-socket level abstraction forces it into unsecure http only..

keegancsmith commented 4 years ago

jsonrpc2 requires bidirectional communication, so if you want to go via http you can upgrade a client connection to websockets. See the websocket package https://godoc.org/github.com/sourcegraph/jsonrpc2/websocket

Alternatively you can create an HTTP handler to do "one-shot" communication. IE a handler which will take in a body of json (which are jsonrpc2 requests) and proxy them on to a jsonrpc2 endpoint. We used to do this at Sourcegraph.