リクエストによって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}}}
のように中括弧を使います。
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy