81
loading...
This website collects cookies to deliver better user experience
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments. It uses JSON (RFC 4627) as data format.
It is designed to be simple!
SwaggerUIBundle
constructor accepts requestInterceptor
in configuration. Provided that JSON-RPC method is available as OpenAPI path item, this interceptor can reroute request and envelope it as JSON-RPC./rpc
in the following code, it is the path to JSON-RPC endpoint, and it may vary from one API to another.requestInterceptor: function(request) {
if (request.loadSpec) {
return request;
}
var url = window.location.protocol + '//'+ window.location.host;
var method = request.url.substring(url.length);
request.url = url + '/rpc';
request.body = '{"jsonrpc": "2.0", "method": "' + method + '", "id": 1, "params": ' + request.body + '}';
return request;
}
Swagger UI
with your JSON-RPC API you need to create a fake OpenAPI schema with structures of your methods.{
"openapi":"3.0.3",
"info":{
"title":"JSON-RPC Example",
"description":"This app showcases a trivial JSON-RPC API.",
"version":"v1.2.3"
},
"paths":{
"nameLength":{
"post":{
"summary":"Test","description":"Test Description",
"operationId":"nameLength",
"requestBody":{
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/JsonrpcTestInp"}}
}
},
"responses":{
"200":{
"description":"OK",
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/JsonrpcTestOut"}}
}
}
}
}
}
},
"components":{
"schemas":{
"JsonrpcTestInp":{"type":"object","properties":{"name":{"type":"string"}}},
"JsonrpcTestOut":{"type":"object","properties":{"len":{"type":"integer"}}}
}
},
"x-envelope":"jsonrpc-2.0"
}
github.com/swaggest/jsonrpc
Go library that serves self-documented JSON-RPC from use case interactors. Support for OpenRPC
might be implemented too.