json-rpc-example

command module
v0.0.0-...-e166aeb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2015 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

json-rpc-example

Example JSON-RPC over HTTP server in Go using Gorilla.

This is a trimmed down example showing how one may use Gorilla JSON-RPC with the mux and middleware.

Usage

Install
go install github.com/bakins/json-rpc-example

Start the server:

json-rpc-example
Make RPC calls using curl
curl  -H "Content-Type: application/json"  -d '{"method":"Arith.Divide","params":[{"A": 10, "B":2}], "id": 0}' http://localhost:8080/rpc
{"id":0,"result":{"Quo":5,"Rem":0},"error":null}

Also supports compressed responses:

curl -sv --compressed -H "Content-Type: application/json" -d '{"method":"Arith.Divide","params":[{"A": 10, "B":2}], "id": 12}' http://localhost:8080/rpc
...
< HTTP/1.1 200 OK
< Content-Encoding: deflate
< Content-Type: application/json; charset=utf-8
< Vary: Accept-Encoding
< X-Content-Type-Options: nosniff
< Date: Wed, 21 Jan 2015 12:26:11 GMT
< Content-Length: 56
<
{"result":{"Quo":5,"Rem":0},"error":null,"id":12}

Additional features

expvar and pprof are availible at their normal endpoints (/debug/vars, etc).

Acknowledgements

Inspired heavily by https://github.com/kelseyhightower/jsonrpc-server

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址