diff --git a/documentation/plain_rules.md b/documentation/plain_rules.md index 64bfa820..467a0b5e 100644 --- a/documentation/plain_rules.md +++ b/documentation/plain_rules.md @@ -200,6 +200,8 @@ The `parameters` field can specify * qs: *optional*, an object with fields and values to build the query string of the URL * json: *optional*, an object that will be sent as JSON. String substitution will be performed in the keys and values of the object's fields. If present, it overrides `template` from `action` +* form: *optional*, an object that will be sent as JSON, for url encoded form data. Header "Content-type: application/x-www-form-urlencoded" is advisable to be present + ```json "action":{ @@ -259,6 +261,28 @@ or use the `json` parameter } } ``` +You can also send form encoded data by using the `form` parameter + +```json + "action": { + "type": "post", + "parameters": { + "url": "http://${target_host}:${target_port}/myapp/${id}", + "headers": { + "Content-type": "application/json", + "X-${type}-pressure": "${BloodPressure}" + }, + "qs": { + "${id}": "${BloodPressure}" + }, + "form": { + "meter": "meter", + "id": "id", + "pressure": "pressure" + } + } + } +``` The `template` and `url` fields and both the field names and the field values of `qs` and `headers` and `json` perform [string substitution](#string-substitution-syntax). diff --git a/lib/models/postAction.js b/lib/models/postAction.js index 243dc6d2..109d6c84 100644 --- a/lib/models/postAction.js +++ b/lib/models/postAction.js @@ -42,6 +42,9 @@ function buildPostOptions(action, event) { else if (action.template) { options.text = myutils.expandVar(action.template, event); } + else if (action.parameters.form) { + options.form = myutils.expandObject(action.parameters.form, event); + } return options; } @@ -62,7 +65,9 @@ function doIt(action, event, callback) { else if (options.text) { requestOptions.body = options.text; } - + else if (options.form){ + requestOptions.form = options.form; + } metrics.IncMetrics(event.service, event.subservice, metrics.actionHttpPost); myutils.requestHelper(options.method.toLowerCase(), requestOptions, function(err, data) {