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

handleRequest -- handle a JSON-RPC request

Description

This method processes an incoming JSON-RPC request. It takes a JSON-encoded string representing a request (or batch of requests) and returns the corresponding JSON-RPC response. It handles method invocation, error handling, and batching automatically. Note that makeRequest is useful for constructing requests.

i1 : server = new JSONRPCServer

o1 = server

o1 : JSONRPCServer
i2 : registerMethod(server, "sum", plus)
i3 : handleRequest(server, makeRequest("sum", {2, 3}, 1))

o3 = {"result": 5, "jsonrpc": "2.0", "id": 1}
i4 : handleRequest(server, makeRequest({("sum", {4, 5}, 2), ("sum", {6, 7}, 3)}))

o4 = [{"result": 9, "jsonrpc": "2.0", "id": 2}, {"result": 13, "jsonrpc":
     "2.0", "id": 3}]

If you need to do any error handling in a method, then the JSONRPCError class may be useful.

Menu

Ways to use handleRequest:

  • handleRequest(JSONRPCServer,String)

For the programmer

The object handleRequest is a method function.


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