Macaulay2 » Documentation
Packages » JSONRPC :: JSONRPC
next | previous | forward | backward | up | index | toc

JSONRPC -- JSONRPC 2.0 server

Description

This package provides a lightweight and flexible implementation of a JSON-RPC 2.0 server, providing an easy way to register and handle remote procedure calls over JSON. It supports method registration, batch processing, and error handling while ensuring compliance with the JSON-RPC specification. The package includes utilities for constructing valid JSON-RPC requests and notifications, making it simple to integrate into existing applications. Designed for reliability and ease of use, it offers built-in logging and a clean, intuitive API for managing JSON-RPC methods.

i1 : server = new JSONRPCServer

o1 = server

o1 : JSONRPCServer
i2 : registerMethod(server, "sum", plus)
i3 : setLogger(server, printerr)
i4 : handleRequest(server, makeRequest("sum", {2, 3}, 1))
 -- received request: {"method": "sum", "id": 1, "jsonrpc": "2.0", "params": [2, 3]}
 -- calling method "sum" with params [2, 3]
 -- method "sum" returned: 5
 -- sending response: {"result": 5, "jsonrpc": "2.0", "id": 1}

o4 = {"result": 5, "jsonrpc": "2.0", "id": 1}

Menu

Author

Version

This documentation describes version 0.1 of JSONRPC, released May 19, 2025.

Citation

If you have used this package in your research, please cite it as follows:

@misc{JSONRPCSource,
  title = {{JSONRPC: JSON-RPC server. Version~0.1}},
  author = {Doug Torrance},
  howpublished = {A \emph{Macaulay2} package available at
    \url{https://github.com/Macaulay2/M2/tree/stable/M2/Macaulay2/packages}}
}

Exports

  • Types
  • Functions and commands
  • Methods
    • handleRequest(JSONRPCServer,String) -- see handleRequest -- handle a JSON-RPC request
    • NewFromMethod(JSONRPCError,ZZ,String) -- see JSONRPCError -- class for JSON-RPC errors
    • NewFromMethod(JSONRPCError,ZZ,String,Thing) -- see JSONRPCError -- class for JSON-RPC errors
    • new JSONRPCServer -- see JSONRPCServer -- JSONRPC server class
    • makeRequest(List) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,HashTable) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,HashTable,String) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,HashTable,ZZ) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,List) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,List,String) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,List,ZZ) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,String) -- see makeRequest -- construct a JSON-RPC request
    • makeRequest(String,ZZ) -- see makeRequest -- construct a JSON-RPC request
    • methods(JSONRPCServer) -- list the methods registered to a JSON-RPC server
    • registerMethod(JSONRPCServer,String,Function) -- see registerMethod -- register a method for a JSON-RPC server
    • registerMethod(JSONRPCServer,String,List,Function) -- see registerMethod -- register a method for a JSON-RPC server
    • setLogger(JSONRPCServer,Function) -- see setLogger -- set up logging for a JSON-RPC server

For the programmer

The object JSONRPC is a package, defined in JSONRPC.m2.


The source of this document is in JSONRPC.m2:229:0.