Files
xrpl-dev-portal/docs/references/http-websocket-apis/api-conventions/request-formatting.md

4.5 KiB

seo
seo
description
Standard request format, with examples, for the WebSocket, JSON-RPC, and Commandline interfaces.

Request Formatting

Example Request

{% tabs %}

{% tab label="WebSocket" %}

{
  "id": "example_ws_request_1",
  "command": "account_info",
  "account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
  "ledger_index": "validated",
  "api_version": 2
}

{% /tab %}

{% tab label="JSON-RPC" %}

POST http://s1.ripple.com:51234/
Content-Type: application/json

{
    "method": "account_info",
    "params": [
        {
            "account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
            "ledger_index": "validated",
            "api_version": 2
        }
    ]
}

{% /tab %}

{% tab label="Commandline" %}

rippled account_info r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59 validated

{% /tab %}

{% /tabs %}

WebSocket Format

After you open a WebSocket to the rippled server, you can send commands as a JSON object with the following fields:

Field Type Description
command String The name of the API method.
id (Various) (Optional) A unique value to identify this request. The response to this request uses the same id field. This way, even if responses arrive out of order, you know which request prompted which response.
api_version Number (Optional) The API version to use. For details, see API Versioning.
(Method Parameters) (Various) Provide any parameters to the method at the top level.

See Response Formatting for the response from the server.

JSON-RPC Format

To make a JSON-RPC request, send an HTTP POST request to the root path (/) on the port and IP where the rippled server is listening for JSON-RPC connections. You can use HTTP/1.0 or HTTP/1.1. If you use HTTPS, you should use TLS version 1.2. For security reasons, rippled does not support SSL version 3 or earlier.

Always include a Content-Type header with the value application/json.

If you plan on making multiple requests, use Keep-Alives so that you do not have to close and re-open the connection in between requests.

Send request body as a JSON object with the following fields:

Field Type Description
method String The name of the API method.
params Array (Optional) A one-item array containing a nested JSON object with the parameters to this method. You may omit this field if the method does not require any parameters.

The object inside the params array can contain the following fields:

Field Type Description
api_version Number (Optional) The API version to use. For details, see API Versioning.
(Method Parameters) (Various) Provide any parameters to the method here.

See Response Formatting for the response from the server.

Commandline Format

Put the API method name after any normal (dash-prefaced) commandline options, followed by a limited set of parameters, separated by spaces. For any parameter values that might contain spaces or other unusual characters, use single-quotes to encapsulate them. Not all methods have commandline API syntax. For more information, see Commandline Usage.

The commandline calls JSON-RPC, so its responses always match the JSON-RPC response format.

The commandline always uses the latest API version.

{% admonition type="warning" name="Caution" %}The commandline interface is intended for administrative purposes only and is not a supported API. New versions of rippled may introduce breaking changes to the commandline API without warning!{% /admonition %}

{% raw-partial file="/docs/_snippets/common-links.md" /%}