リクエストの送信
REST APIへのアクセス時のリクエストおよびレスポンスのJSON形式
HTTPのリクエストおよびレスポンスでは、IO処理に、HTTPコンテンツ内のJSONが使用されます。
JSONペイロード
一般的なHTTPリクエスト・ペイロード(ログイン・リクエストは異なる)は、次のような構造になります。
{
"command" : "operation/command name"
"arguments" : [
{"argumentName":"value"},
{"argumentName":"value"},
{"argumentName":"value"}
]
}
command
フィールドは、管理CLI内の、単一のコマンド、またはサブコマンドがある1つのコマンドにマップされます。arguments
フィールドにより、そのコマンドの引数と値が、JSON配列構造内のコマンド・サービスに渡されます。
deploy-sn
コマンドの場合のJSONペイロードの例を次に示します。
{
"command" : "deploy-sn"
"arguments" : [
{"zn":"zn1"},
{"host": "localhost"},
{"port":5000}
]
}
arguments
の配列値はJSONオブジェクトです。各JSONオブジェクトには、名前/値のペアを含むエントリが1つのみ存在します。エントリの名前は、コマンドの引数の名前です。エントリの値は、コマンドの引数の値です。arguments
フィールド内の引数名/値のペアは、管理CLIコマンドと同じ順序である必要があります。
エントリの名前は、次のパターンに従っている必要があります。
argumentNameWithMutiplePart
この名前は、管理CLIの引数名に変換されます。
-argument-name-with-multiple-part
引数値には、文字列またはブールを指定できます。たとえば:
{"zn": "stringValueOfZnId"}
{"port": "5000"}
{"useArbiter": true}
ブール引数値がtrue
に設定されている場合、コマンドラインで解析されます。前述の例では、コマンドラインで{"useArbiter": true},
が-use-arbiter
に解析されます。
レスポンス
HTTPレスポンス内のJSONペイロードは、結果を示す次のような構造になります。
{
operation : string
returnCode : string
description : string
returnValue : object
}
{
"operation" : "command name or specific operation name"
"returnCode" : "error code range from 5000 to 5500 to indicate failure, 5000 is successful"
"description" : "description of the result, it could be text result of the command output if information need to be read manually by administrator"
"returnValue" : "Useful information structured in JSON format to allow application to handle the result automatically"
}
{
"operation":"Command related operation",
"returnCode":"Error code to indicate the command result, 5000 infers plan success, 5100 infers illegal command, 5200 - 5500 infers connection/resource/internal problem of executing plan.",
"description":"Textual output of the command",
"returnValue":"Valuable information returned by the command execution in JSON object format"
}
すべての管理WebサービスAPIは、HTTPレスポンス・ペイロード内のJSONを返します。結果のJSONペイロードは管理CLIコマンドのJSON出力にマップされるため、その結果は、管理CLIコマンドで-json
オプションを使用する場合と同じです。