Batch JSON-RPCs in Go with Gorilla RPC -


OK, so I'm working on a server. It works in web pages and offers other services.

  Package main import ("fmt" "logon" "net / http" "github.com/gorilla/rpc" "github.com/gorilla/rpc / json") Type service struct {name} string type ServiceArgs struct {Str string Val float64} type ServiceReply struct {message string} function (e-Services) DoSomething (request * http.Request, args * ServiceArgs, North * ServiceReply) error {Fmt.Println ( "DoSomething Is called away! ") Answer Message = "OMG, it works." Return nil} function main () {rpcHandler: = rpc.NewServer () rpcHandler.RegisterCodec (json.NewCodec (), "application / json") rpcHandler.RegisterService (new (service), "") http.Handle ( "/ RPC", rpcHandler) http.Handle ( "/", http.StripPrefix ( "/", hearing http.FileServer (http.Dir ( ".")))) fmt.Println ( "" on port 8080) that An: = Http.ListenAndServe (": 8080", zero); mistake! = Zero {log. Fatalin (mistake)}}  

I have an API on the server side, which I want to reach the normal customer. For this, I started learning more about JSON-RPC. In this way I service from any web browser. Call me anything .

  var log = document.getElementById ("logs"); Var Requests = New XMLHttpRequest (); "{0}", "id": 1} "command": "2.0", "method": "service. Dotsing", "params": [{"Str": "pie", "val": 3.14} ], "Id"; Request.onreadystatechange = function () {if (request.readyState == 4 & request.status == 200) {var response = JSON.parse (request.responseText) .result; Log.textContent + = Response ["Message"]; } And {console.log (request.statusText); }}; Request.open ("post", "/ rpc", true); Request.setRequestHeader ("content-type", "app / jason; charset = utf-8"); Request.send (json.stringify (command));  

This works fine, "OMG, it works." After I started javascript in my browser, I wanted to run several method calls. I found that there is a way to send "batch" of calls to the server, so I tried it with javascript.

  var command = [[ "jsonrpc": "2.0", "method": "service. Dusnmeling", "Params": [{ "Str", "could", "Val" : 3.14}], "id": 1}, { "jsonrpc": "2.0", "method": "ServicekDoSomething" "parameters": [{ "Str": "pie", "Val": 3.14} ], "Id": 2}]; Request.send (json.stringify (command));  

However, it gives me a 400 (bad request) . Did I screw the syntax somewhere? Or is there a problem with gorilla / rpc ?

According to:

This package contains JSON-RPC 1.0 specification Type is:.

, and, in accordance with the 'batch' is a JSON-RPC 2.0 feature

It seems that gorillas JSON-RPC does not understand batch queries made is.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -