This library provides procedures handling JSON RPC 2.0.
This library doesn't provide transport layer. To send request and receive response, use Http transport.
This library uses JSON parser library and its JSON representation.
Following piece of code describes how to use;
(import (rnrs) (rpc json) (rpc transport http))
(define (json-rpc-send&request url method param)
(let ((request (make-json-request method :param param)))
(let-values (((status header response) (rpc-http-request url request)))
;; rpc-http-request unmarshalls only when HTTP status starts with "2"
;; for this example we don't check it.
(json-response-result response))))
(json-rpc-send&request "http://localhost/json-rpc" "sample" "parameter")
;; -> result of method execution
These classes represents JSON RPC request and response respectively.
The class instance should be created by make-json-request
,
json-string->json-request
or json-string->json-response
. Users
should not create an instance directly using make
.
Returns #t if the given object is an instance of
<json-request>
and <json-response>
respectively.
Creates a JSON RPC request.
method must be a symbol or string represents method name to be invoked.
The keyword argument params is the params
field of the JSON
RPC protocol.
The keyword argument id is the id
field of the JSON RPC protocol.
If this is not specified then a value generated by UUID v4 will be used.
Creates JSON RPC request and response from given JSON string json.
Retrieves JSON RPC request's method, params and id respectively from given json request object json-request.
Retrieves JSON RPC response's result and id respectively from given json response object json-response.
Converts given json-request and json-response to JSON string.
Following methods are currently used only in (rpc http transport)
.
When we support other transport, this implementation may change.
Converts to given JSON RPC request object to UTF8 bytes.
Converts to given UTF8 bytes to JSON RPC response object.
Returns application/json
content type header value
Returns json
symbol.