2013-09-05 16:02:48 +02:00
<!--
Copyright 2013 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
< script type = "text/x-red" data-template-name = "http in" >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-method" > < i class = "fa fa-tasks" > < / i > < span data-i18n = "httpin.label.method" > < / span > < / label >
2014-06-08 16:05:08 +02:00
< select type = "text" id = "node-input-method" style = "width:72%;" >
2013-09-05 16:02:48 +02:00
< option value = "get" > GET< / option >
< option value = "post" > POST< / option >
< option value = "put" > PUT< / option >
< option value = "delete" > DELETE< / option >
< / select >
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-url" > < i class = "fa fa-globe" > < / i > < span data-i18n = "httpin.label.url" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-url" placeholder = "/url" >
2013-09-05 16:02:48 +02:00
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2013-09-05 16:02:48 +02:00
< / div >
2015-04-24 20:53:38 +02:00
< div class = "form-row row-swagger-doc" >
2015-07-14 00:21:03 +02:00
< label for = "node-input-swaggerDoc" > < i class = "fa fa-tag" > < / i > < span data-i18n = "httpin.label.doc" > < / span > < / label >
2015-04-24 20:53:38 +02:00
< input type = "text" id = "node-input-swaggerDoc" >
< / div >
2015-05-26 22:11:14 +02:00
< div id = "node-input-tip" class = "form-tips" > < span data-i18n = "httpin.tip.in" > < / span > < code > < span id = "node-input-path" > < / span > < / code > .< / div >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/x-red" data-help-name = "http in" >
2014-06-08 16:05:08 +02:00
< p > Provides an input node for http requests, allowing the creation of simple web services.< / p >
< p > The resulting message has the following properties:
< ul >
< li > msg.req : < a href = "http://expressjs.com/api.html#req" > http request< / a > < / li >
< li > msg.res : < a href = "http://expressjs.com/api.html#res" > http response< / a > < / li >
< / ul >
2013-09-05 16:02:48 +02:00
< / p >
2014-06-08 16:05:08 +02:00
< p > For POST/PUT requests, the body is available under < code > msg.req.body< / code > . This
uses the < a href = "http://expressjs.com/api.html#bodyParser" > Express bodyParser middleware< / a > to parse the content to a JSON object.
2013-09-05 16:02:48 +02:00
< / p >
2014-06-08 16:05:08 +02:00
< p >
By default, this expects the body of the request to be url encoded:
< pre > foo=bar& this=that< / pre >
< / p >
< p >
To send JSON encoded data to the node, the content-type header of the request must be set to
< code > application/json< / code > .
< / p >
< p >
2015-06-03 23:52:48 +02:00
< b > Note: < / b > This node does not send any response to the http request.
This should be done with a subsequent HTTP Response node.
2013-09-05 16:02:48 +02:00
< / p >
< / script >
2013-09-28 23:18:41 +02:00
< script type = "text/x-red" data-template-name = "http response" >
2013-10-01 18:03:17 +02:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2013-10-01 18:03:17 +02:00
< / div >
2015-05-26 22:11:14 +02:00
< div class = "form-tips" > < span data-i18n = "[html]httpin.tip.res" > < / span > < / div >
2013-09-28 23:18:41 +02:00
< / script >
2013-09-05 16:02:48 +02:00
2013-09-28 23:18:41 +02:00
< script type = "text/x-red" data-help-name = "http response" >
2014-06-08 16:05:08 +02:00
< p > Sends responses back to http requests received from an HTTP Input node.< / p >
< p > The response can be customised using the following message properties:< / p >
< ul >
2014-07-14 10:26:09 +02:00
< li > < code > payload< / code > is sent as the body of the response< / li >
2014-06-08 16:05:08 +02:00
< li > < code > statusCode< / code > , if set, is used as the response status code (default: 200)< / li >
< li > < code > headers< / code > , if set, should be an object containing field/value
pairs to be added as response headers.< / li >
< / ul >
2013-09-28 23:18:41 +02:00
< / script >
2013-10-01 18:03:17 +02:00
< script type = "text/x-red" data-template-name = "http request" >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-method" > < i class = "fa fa-tasks" > < / i > < span data-i18n = "httpin.label.method" > < / span > < / label >
2014-06-08 16:05:08 +02:00
< select type = "text" id = "node-input-method" style = "width:72%;" >
2013-10-01 18:03:17 +02:00
< option value = "GET" > GET< / option >
< option value = "POST" > POST< / option >
< option value = "PUT" > PUT< / option >
< option value = "DELETE" > DELETE< / option >
2015-05-10 22:47:22 +02:00
< option value = "use" data-i18n = "httpin.setby" > < / option >
2013-10-01 18:03:17 +02:00
< / select >
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-url" > < i class = "fa fa-globe" > < / i > < span data-i18n = "httpin.label.url" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-url" placeholder = "http://" >
2013-10-01 18:03:17 +02:00
< / div >
2014-02-19 21:31:42 +01:00
< div class = "form-row" >
< label > < / label >
< input type = "checkbox" id = "node-input-useAuth" style = "display: inline-block; width: auto; vertical-align: top;" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-useAuth" style = "width: 70%;" > < span data-i18n = "httpin.basicauth" > < / span > < / label >
2014-02-19 21:31:42 +01:00
< / div >
< div class = "form-row node-input-useAuth-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-user" > < i class = "fa fa-user" > < / i > < span data-i18n = "common.label.username" > < / span > < / label >
2014-07-19 01:22:58 +02:00
< input type = "text" id = "node-input-user" >
2014-02-19 21:31:42 +01:00
< / div >
< div class = "form-row node-input-useAuth-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-password" > < i class = "fa fa-lock" > < / i > < span data-i18n = "common.label.password" > < / span > < / label >
2014-07-19 01:22:58 +02:00
< input type = "password" id = "node-input-password" >
2014-02-19 21:31:42 +01:00
< / div >
2014-12-09 15:40:03 +01:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-ret" > < i class = "fa fa-arrow-left" > < / i > < span data-i18n = "httpin.label.return" > < / span > < / label >
2014-12-09 15:40:03 +01:00
< select type = "text" id = "node-input-ret" style = "width:72%;" >
2015-05-10 22:47:22 +02:00
< option value = "txt" data-i18n = "httpin.utf8" > < / option >
< option value = "bin" data-i18n = "httpin.binary" > < / option >
< option value = "obj" data-i18n = "httpin.json" > < / option >
2014-12-09 15:40:03 +01:00
< / select >
< / div >
2013-10-01 18:03:17 +02:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2013-10-01 18:03:17 +02:00
< / div >
2015-05-26 22:11:14 +02:00
< div class = "form-tips" id = "tip-json" hidden > < span data-i18n = "httpin.tip.req" > < / span > < / div >
2013-10-01 18:03:17 +02:00
< / script >
< script type = "text/x-red" data-help-name = "http request" >
2014-06-08 16:05:08 +02:00
< p > Provides a node for making http requests.< / p >
2014-11-03 14:41:45 +01:00
< p > The URL and HTTP method can be configured in the node, if they are left blank they should be set in an incoming message on < code > msg.url< / code > and < code > msg.method< / code > :< / p >
2014-06-08 16:05:08 +02:00
< ul >
2014-07-23 13:09:21 +02:00
< li > < code > url< / code > , if set, is used as the url of the request. Must start with http: or https:< / li >
< li > < code > method< / code > , if set, is used as the HTTP method of the request.
2015-01-30 10:59:36 +01:00
Must be one of < code > GET< / code > , < code > PUT< / code > , < code > POST< / code > , < code > PATCH< / code > or < code > DELETE< / code > (default: GET)< / li >
2014-06-08 16:05:08 +02:00
< li > < code > headers< / code > , if set, should be an object containing field/value
pairs to be added as request headers< / li >
< li > < code > payload< / code > is sent as the body of the request< / li >
< / ul >
< p > When configured within the node, the URL property can contain < a href = "http://mustache.github.io/mustache.5.html" target = "_new" > mustache-style< / a > tags. These allow the
url to be constructed using values of the incoming message. For example, if the url is set to
2015-03-16 21:22:25 +01:00
< code > example.com/{{{topic}}}< / code > , it will have the value of < code > msg.topic< / code > automatically inserted.
Using {{{...}}} prevents mustache from escaping characters like / & etc.< / p >
2014-06-08 16:05:08 +02:00
< p >
The output message contains the following properties:
< ul >
< li > < code > payload< / code > is the body of the response< / li >
< li > < code > statusCode< / code > is the status code of the response, or the error code if the request could not be completed< / li >
< li > < code > headers< / code > is an object containing the response headers< / li >
< / ul >
2015-05-19 10:45:00 +02:00
< p > < b > Note< / b > : If you need to configure a proxy please add < b > http_proxy=...< / b > to your environment variables and restart Node-RED.< / p >
2013-10-01 18:03:17 +02:00
< / script >
< script type = "text/javascript" >
2014-04-15 23:49:39 +02:00
RED.nodes.registerType('http in',{
category: 'input',
color:"rgb(231, 231, 174)",
defaults: {
name: {value:""},
url: {value:"",required:true},
2015-04-24 20:53:38 +02:00
method: {value:"get",required:true},
2015-07-08 23:12:52 +02:00
swaggerDoc: {type:"swagger-doc", required:false}
2014-04-15 23:49:39 +02:00
},
inputs:0,
outputs:1,
icon: "white-globe.png",
label: function() {
if (this.name) {
return this.name;
} else if (this.url) {
2014-10-08 12:03:18 +02:00
var root = RED.settings.httpNodeRoot;
2014-11-03 14:41:45 +01:00
if (root.slice(-1) != "/") {
2014-10-08 12:03:18 +02:00
root = root+"/";
}
if (this.url.charAt(0) == "/") {
root += this.url.slice(1);
} else {
root += this.url;
}
2014-04-15 23:49:39 +02:00
return "["+this.method+"] "+root;
} else {
return "http";
}
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
2014-10-08 12:03:18 +02:00
var root = RED.settings.httpNodeRoot;
2014-11-03 14:41:45 +01:00
if (root.slice(-1) == "/") {
2014-10-08 12:03:18 +02:00
root = root.slice(0,-1);
}
2014-04-15 23:49:39 +02:00
if (root == "") {
$("#node-input-tip").hide();
} else {
$("#node-input-path").html(root);
$("#node-input-tip").show();
}
2015-05-13 14:54:47 +02:00
if(!RED.nodes.getType("swagger-doc")){
$('.row-swagger-doc').hide();
}
2014-04-15 23:49:39 +02:00
}
});
2014-06-08 16:05:08 +02:00
2014-04-15 23:49:39 +02:00
RED.nodes.registerType('http response',{
category: 'output',
color:"rgb(231, 231, 174)",
defaults: {
name: {value:""}
},
inputs:1,
outputs:0,
align: "right",
icon: "white-globe.png",
label: function() {
return this.name||"http";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
2014-06-08 16:05:08 +02:00
2013-10-01 18:03:17 +02:00
RED.nodes.registerType('http request',{
category: 'function',
color:"rgb(231, 231, 174)",
defaults: {
name: {value:""},
method:{value:"GET"},
2014-12-09 15:40:03 +01:00
ret: {value:"txt"},
2014-02-19 21:31:42 +01:00
url:{value:""},
//user -> credentials
//pass -> credentials
2013-10-01 18:03:17 +02:00
},
2014-07-19 01:22:58 +02:00
credentials: {
user: {type:"text"},
password: {type: "password"}
},
2013-10-01 18:03:17 +02:00
inputs:1,
outputs:1,
icon: "white-globe.png",
label: function() {
2015-05-10 22:47:22 +02:00
return this.name||this._("httpin.httpreq");
2013-09-28 23:18:41 +02:00
},
labelStyle: function() {
2013-10-01 18:03:17 +02:00
return this.name?"node_label_italic":"";
2014-02-19 21:31:42 +01:00
},
oneditprepare: function() {
2014-07-20 21:42:41 +02:00
if (this.credentials.user || this.credentials.has_password) {
2014-07-19 01:22:58 +02:00
$('#node-input-useAuth').prop('checked', true);
$(".node-input-useAuth-row").show();
} else {
$('#node-input-useAuth').prop('checked', false);
$(".node-input-useAuth-row").hide();
}
2014-06-08 16:05:08 +02:00
2014-02-19 21:31:42 +01:00
$("#node-input-useAuth").change(function() {
if ($(this).is(":checked")) {
$(".node-input-useAuth-row").show();
} else {
$(".node-input-useAuth-row").hide();
2014-07-19 01:22:58 +02:00
$('#node-input-user').val('');
$('#node-input-password').val('');
2014-02-19 21:31:42 +01:00
}
});
2014-12-09 15:40:03 +01:00
$("#node-input-ret").change(function() {
if ($("#node-input-ret").val() === "obj") {
$("#tip-json").show();
} else {
$("#tip-json").hide();
}
});
}
2013-09-28 23:18:41 +02:00
});
2013-09-05 16:02:48 +02:00
< / script >