mjsonrpc 1.0
A lightweight JSON-RPC 2.0 message parser and generator based on cJSON
Loading...
Searching...
No Matches
Functions
Client API

Functions for creating JSON-RPC requests (client side) More...

Functions

char * mjrpc_request_str (const char *method, cJSON *params, cJSON *id)
 Build a JSON-RPC request as a string.
 
cJSON * mjrpc_request_cjson (const char *method, cJSON *params, cJSON *id)
 Build a JSON-RPC request as a cJSON object.
 

Detailed Description

Functions for creating JSON-RPC requests (client side)

Function Documentation

◆ mjrpc_request_cjson()

cJSON * mjrpc_request_cjson ( const char *  method,
cJSON *  params,
cJSON *  id 
)

Build a JSON-RPC request as a cJSON object.

Creates a JSON-RPC 2.0 request as a cJSON object with the specified method, parameters, and request ID. The parameters and ID will be owned by the request.

Parameters
methodName of the RPC method to call (must not be NULL)
paramsParameters for the method (can be NULL, will be owned by request)
idRequest ID (can be NULL for notification, will be owned by request)
Returns
cJSON pointer containing the JSON-RPC request (caller must delete)
Return values
NULLIf an error occurred (params and id will still be released)
Note
For notification requests, pass NULL as the id parameter
Example:
cJSON *params = cJSON_CreateArray();
cJSON_AddItemToArray(params, cJSON_CreateString("arg1"));
cJSON *id = cJSON_CreateString("req-123");
cJSON *request = mjrpc_request_cjson("method", params, id);
if (request) {
// Use request...
cJSON_Delete(request);
}
cJSON * mjrpc_request_cjson(const char *method, cJSON *params, cJSON *id)
Build a JSON-RPC request as a cJSON object.

◆ mjrpc_request_str()

char * mjrpc_request_str ( const char *  method,
cJSON *  params,
cJSON *  id 
)

Build a JSON-RPC request as a string.

Creates a JSON-RPC 2.0 request string with the specified method, parameters, and request ID. The parameters and ID will be released (freed) automatically.

Parameters
methodName of the RPC method to call (must not be NULL)
paramsParameters for the method (can be NULL, will be released)
idRequest ID (can be NULL for notification, will be released)
Returns
String pointer containing the JSON-RPC request (caller must free)
Return values
NULLIf an error occurred (params and id will still be released)
Note
For notification requests, pass NULL as the id parameter
Example:
cJSON *params = cJSON_CreateObject();
cJSON_AddStringToObject(params, "name", "world");
cJSON *id = cJSON_CreateNumber(1);
char *request = mjrpc_request_str("hello", params, id);
if (request) {
// Send request...
free(request);
}
char * mjrpc_request_str(const char *method, cJSON *params, cJSON *id)
Build a JSON-RPC request as a string.