IntelliJ IDEA 2026.1 Help

HTTP クライアントでサポートされる JavaScript API

console.log

HTTP クライアントは、応答ハンドラーまたは事前要求ハンドラースクリプトの出力にテキスト値 (またはコンマで区切られた複数の値) を出力する console.log() メソッドをサポートしています。 同じ目的に client.log を使用することもできます。 例:

GET example.org > {% console.log(response.status) %}

JavaScript オブジェクト (console.log(response.body) など) を渡すこともでき、そのオブジェクトは適切な構文ハイライトとともに JSON 形式で出力に表示されます。

DOM メソッドとプロパティ

HTTP クライアントは、レスポンス本文の一部として受信した (または DOMParser を使用して作成された) XML および HTML ドキュメントを解析および操作できる DOM ツリーメソッドとプロパティの一部をサポートしています。 サポートされているメソッドは次のとおりです。

getElementsByTagName()

指定されたタグ名を持つ要素のコレクションを返します。 例:

GET https://examples.http-client.intellij.net/xml > {% const slide = response.body.getElementsByTagName("slide")[0] console.log(slide) %}
getElementsByName()

指定された name 属性を持つノードのコレクションを返します。 例:

getElementById()

id によって Element オブジェクトを取得します。

getElementsByClassName()

指定されたクラス名を持つすべての子要素の配列のようなオブジェクトを返します。

DOMParser

parseFromString() メソッドを使用して、文字列から XML または HTML ソースコードを DOM ドキュメントに解析します。 例:

GET example.org > {% const xmlStr = '<q id="a"><span class="test" id="b">hey!</span><span id="bar">world</span><foo class="test" id="x-foo"/><bar name="x-foo"/></q>'; const doc = new DOMParser().parseFromString(xmlStr, "application/xml"); console.log(doc.getElementById("a")) console.log(doc.getElementById("b")) console.log(doc.getElementsByClassName("test")) console.log(doc.getElementsByTagName("span")) console.log(doc.getElementsByName("x-foo")) %}
createElement(tagName)

tagName で指定された HTML 要素を作成します。

GET example.org > {% const xmlStr = '<q id="a"><span class="test" id="b">hey!</span><span id="bar">world</span><foo class="test" id="x-foo"/><bar name="x-foo"/></q>'; const doc = new DOMParser().parseFromString(xmlStr, "application/xml"); const bodyElement = doc.createElement("body"); %}

メソッド名を入力し始めると、サポートされているメソッドの補完が表示されます。 マウスをその上に移動すると、簡単なドキュメントが表示されます。 サポートされているすべての DOM メソッドとプロパティを表示するには、以下のセクションを展開します。

サポートされているプロパティ

URLSearchParams

URLSearchParams は、URL のクエリ文字列部分の操作を容易にする JavaScript オブジェクトです。 URLSearchParams は、次の形式のパラメーターを受け入れます。

  • クエリ文字列: URLSearchParams("key=value&key2=value2");

  • URL パラメーターを表すキーと値のペア: URLSearchParams({ key1: "value1", key2: "value2" })

  • キーと値のペアの配列: URLSearchParams([["key1", "value1"], ["key2", "value2"]])

HTTP クライアントは、 既知の URLSearchParams メソッドをすべてサポートします。 例:

< {% client.global.set('query', 'foo=1&bar=2') const params = new URLSearchParams(client.global.get('query')); const params2 = new URLSearchParams([["planet", "tatooine"], ["year", "2"]]); const params3 = new URLSearchParams({key1: "value1", key2: "value2"}); console.log(params.has("bar")); // outputs true console.log(params.has("param")); // outputs false params.append("foo", 3); console.log(params.getAll("foo")); // outputs ["1","3"] for (let value of params.values()) { console.log(value); // outputs 1 2 3 } for (let key of params2.keys()) { console.log(key); // outputs planet year } client.global.set("query",params.toString()) %} GET example.org/{{query}}

Base64 エンコーディング: btoa と atob

HTTP クライアントは、 btoa() および atob() メソッドをサポートしています。

  • Window.btoa(stringToEncode) または btoa(stringToEncode) を使用して、 stringToEncode 文字列から Base64 でエンコードされた ASCII 文字列を作成します。

  • Window.atob(encodedData) または atob(encodedData) を使用して、Base64 でエンコードされたデータの文字列をデコードします。

例:

GET https://examples.http-client.intellij.net/ip > {% const encodedData = Window.btoa("Hello, world"); // encode a string const decodedData = Window.atob(encodedData); // decode the string console.log(decodedData); // prints "Hello, world" %}

シェルコマンドを実行する

シェル コマンドを実行することでオペレーティングシステムと連携できるように、HTTP Client は次のメソッドをサポートしています。

exec(command[, options][, callback])

シェルを生成し、そのシェル内でコマンドを実行し、生成された出力をバッファリングします。

execFile(file[, args][, options][, callback])

デフォルトではシェルを生成しないことを除けば、 exec() と似ています。

execSync(command[, options])

子プロセスが完全に閉じられるまでメソッドが返されない点を除いて、 exec() と同じです。

execFileSync(file[, args][, options])

子プロセスが完全に閉じられるまでメソッドが返されない点を除いて、 execFile() と同じです。

spawn(command[, args][, options])

シェルを生成し、そのシェル内でコマンドを実行し、生成された出力をバッファリングします。

spawnSync(command[, args][, options])

子プロセスが完全に閉じられるまで関数が返されない点を除いて、 spawn() と同じです。

サポートされているオプションは次のとおりです。

cwd

コマンドを実行するディレクトリを指定します。

env

プロセスで利用可能な環境変数の設定を指定します。

timeout

プロセスが実行を許可される最大時間(ミリ秒単位)を指定します。

maxBuffer

出力のサイズに対する最大制限(文字数)を設定します。

shell

コマンドを実行するシェルを指定します。

signal

プロセスを終了させる際に送信されるシグナルを指定します。

callback

オプションではなく、非同期メソッドに渡すことができる別のパラメーターです。 プロセス終了時に呼び出される関数がコールバックです。

例:

### List all directories in the specified folder GET https://examples.http-client.intellij.net > {% const result = execSync("ls -l", { cwd: '/Users/John.Doe/Docs/' }) console.log(`result: ${result}`) %} ### Pass an environment variable to the process < {% const result = execSync('bash -c "set"', { env : { name: 'John' }}) console.log(`result: ${result}`) %} GET https://examples.http-client.intellij.net
2026 年 3 月 30 日