Sign inSign up

fboranek/barrister-example

By fboranek

•Updated over 9 years ago

Image
0

841

fboranek/barrister-example repository overview

⁠barrister-example

Test server with JSON-RPC 2.0 ("Hello world" example).

The example uses barrister⁠ to generate API from IDL for Node.js.

This test server has implemented folowing interfce:

interface Calculator {

    float add(a float, b float);
    float subtract(a float, b float); 
}

The server is lissen on port 80. You can run it via docker

docker run -it -p 8888:80 fboranek/barrister-example

and then server will be visible on port 8888. The HTTP POST request must be send on URL http://localhost/jsonrpc⁠ where a JSON-RPC handler is and must have the content type application/json.

The JSON-RPC 2.0 specifies 2 ways how to send parameters of a function. Fist option is using array where request should look like:

POST /calc HTTP/1.1
Host: localhost
Accept: */*
Content-Type: application/json
Content-Length: 93

{
   "jsonrpc" : "2.0",
   "method" : "Calculator.add",
   "params" : [ 10, 3],
   "id" : 1
}

This is the way which barrister uses. The second option is to use named parameters. The advantage is these parameters can be optional. However, it is not possible using barrister. So folowing HTTP request is not valid for this server.

POST /calc HTTP/1.1
Host: localhost
Accept: */*
Content-Type: application/json
Content-Length: 105

{
   "jsonrpc" : "2.0",
   "method" : "Calculator.add",
   "params" : { "a" : 10, "b" : 3 },
   "id" : 1
}

Respond from server looks like:

HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 36
ETag: W/"24-q4pl6Shex+06JjDH0NLApsVOHy8"
Date: Mon, 20 Mar 2017 11:09:24 GMT
Connection: keep-alive

{"jsonrpc":"2.0","id":1,"result":13}

Tag summary

Content type

Image

Digest

Size

248.2 MB

Last updated

over 9 years ago

docker pull fboranek/barrister-example