リクエスト先URLにテンプレートを使用

課題

リクエストによってURLの一部のみが変更になるような、HTTPリクエストのURLを動的に設定したい。

解決

mustache URLテンプレートを使用して URLを動的に設定するよう HTTP Request ノードを設定します。

このフローでは Inject ノードがリクエストするAPIに送信するpostのidを送ります。 Change ノードはこれを msg.post に代入します。 HTTP Request ノードは、次に示すように設定されたURLプロパティを msg.post で置換することにより送信先のURLを生成します。

https://jsonplaceholder.typicode.com/posts/{{post}}

The JSON output from this API in the debug panel will look as follows:

{
  "userId": 1,
  "id": 2,
  "title": "qui est esse",
  "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
}

議論

デフォルトでは、mustacheは値の中のHTMLエンティティをエスケープします。 URLエスケープが効かないようにするには {{{triple}}} のように中括弧を使います。