2013-09-05 16:02:48 +02:00
|
|
|
<!--
|
2017-01-11 16:24:33 +01:00
|
|
|
Copyright JS Foundation and other contributors, http://js.foundation
|
2013-09-05 16:02:48 +02:00
|
|
|
|
|
|
|
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>
|
2016-06-27 00:48:59 +02:00
|
|
|
<select type="text" id="node-input-method" style="width:70%;">
|
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>
|
2016-06-08 12:31:59 +02:00
|
|
|
<option value="patch">PATCH</option>
|
2013-09-05 16:02:48 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2017-01-16 23:39:30 +01:00
|
|
|
<div class="form-row form-row-http-in-upload hide">
|
|
|
|
<label> </label>
|
|
|
|
<input type="checkbox" id="node-input-upload" style="display: inline-block; width: auto; vertical-align: top;">
|
|
|
|
<label for="node-input-upload" style="width: 70%;" data-i18n="httpin.label.upload"></label>
|
|
|
|
</div>
|
2013-09-05 16:02:48 +02:00
|
|
|
<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>
|
2016-10-28 09:37:33 +02:00
|
|
|
<input id="node-input-url" type="text" 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-09-28 00:49:14 +02:00
|
|
|
<label for="node-input-swaggerDoc"><i class="fa fa-file-text-o"></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">
|
2017-05-24 17:55:53 +02:00
|
|
|
<p>Creates an HTTP end-point for creating web services.</p>
|
|
|
|
<h3>Outputs</h3>
|
|
|
|
<dl class="message-properties">
|
|
|
|
<dt>payload</dt>
|
|
|
|
<dd>For a GET request, contains an object of any query string parameters.
|
|
|
|
Otherwise, contains the body of the HTTP request.</dd>
|
|
|
|
<dt>req<span class="property-type">object</span></dt>
|
|
|
|
<dd>An HTTP request object. This object contains multiple properties that
|
|
|
|
provide information about the request.
|
|
|
|
<ul>
|
|
|
|
<li><code>body</code> - the body of the incoming request. The format
|
|
|
|
will depend on the request.</li>
|
|
|
|
<li><code>headers</code> - an object containing the HTTP request headers.</li>
|
|
|
|
<li><code>query</code> - an object containing any query string parameters.</li>
|
|
|
|
<li><code>params</code> - an object containing any route parameters.</li>
|
|
|
|
<li><code>cookies</code> - an object containing the cookies for the request.</li>
|
2017-06-28 18:15:42 +02:00
|
|
|
<li><code>files</code> - if enabled within the node, an object containing
|
2017-05-24 17:55:53 +02:00
|
|
|
any files uploaded as part of a POST request.</li>
|
|
|
|
</ul>
|
|
|
|
</dd>
|
|
|
|
<dt>res<span class="property-type">object</span></dt>
|
|
|
|
<dd>An HTTP response object. This property should not be used directly;
|
|
|
|
the <code>HTTP Response</code> node documents how to respond to a request.
|
|
|
|
This property must remain attached to the message passed to the response node.</dd>
|
|
|
|
</dl>
|
|
|
|
<h3>Details</h3>
|
|
|
|
<p>The node will listen on the configured path for requests of a particular type.
|
|
|
|
The path can be fully specified, such as <code>/user</code>, or include
|
|
|
|
named parameters that accept any value, such as <code>/user/:name</code>.
|
|
|
|
When named parameters are used, their actual value in a request can be accessed under `msg.req.params`.</p>
|
|
|
|
<p>For requests that include a body, such as a POST or PUT, the contents of
|
|
|
|
the request is made available as <code>msg.payload</code>.</p>
|
|
|
|
<p>If the content type of the request can be determined, the body will be parsed to
|
|
|
|
any appropriate type. For example, <code>application/json</code> will be parsed to
|
|
|
|
its JavaScript object representation.</p>
|
|
|
|
<p><b>Note:</b> this node does not send any response to the request. The flow
|
|
|
|
must include an HTTP Response node to complete the request.</p>
|
2013-09-05 16:02:48 +02:00
|
|
|
</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>
|
2017-01-24 15:56:48 +01:00
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-statusCode"><i class="fa fa-long-arrow-left"></i> <span data-i18n="httpin.label.status"></span></label>
|
|
|
|
<input type="text" id="node-input-statusCode" placeholder="msg.statusCode">
|
|
|
|
</div>
|
|
|
|
<div class="form-row" style="margin-bottom:0;">
|
|
|
|
<label><i class="fa fa-list"></i> <span data-i18n="httpin.label.headers"></span></label>
|
|
|
|
</div>
|
|
|
|
<div class="form-row node-input-headers-container-row">
|
|
|
|
<ol id="node-input-headers-container"></ol>
|
|
|
|
</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">
|
2017-05-24 17:55:53 +02:00
|
|
|
<p>Sends responses back to requests received from an HTTP Input node.</p>
|
|
|
|
|
|
|
|
<h3>Inputs</h3>
|
|
|
|
<dl class="message-properties">
|
|
|
|
<dt>payload <span class="property-type">string</span></dt>
|
|
|
|
<dd>The body of the response.</dd>
|
|
|
|
<dt class="optional">statusCode <span class="property-type">number</span></dt>
|
|
|
|
<dd>If set, this is used as the response status code. Default: 200.</dd>
|
|
|
|
<dt class="optional">headers <span class="property-type">object</span></dt>
|
|
|
|
<dd>If set, provides HTTP headers to include in the response.</dd>
|
|
|
|
<dt class="optional">cookies <span class="property-type">object</span></dt>
|
|
|
|
<dd>If set, can be used to set or delete cookies.</dd>
|
|
|
|
</dl>
|
|
|
|
<h3>Details</h3>
|
2017-01-24 15:56:48 +01:00
|
|
|
<p>The <code>statusCode</code> and <code>headers</code> can also be set within
|
|
|
|
the node itself. If a property is set within the node, it cannot be overridden
|
|
|
|
by the corresponding message property.</p>
|
2017-05-24 17:55:53 +02:00
|
|
|
<h4>Cookie handling</h4>
|
2016-06-08 12:09:18 +02:00
|
|
|
<p>The <code>cookies</code> property must be an object of name/value pairs.
|
|
|
|
The value can be either a string to set the value of the cookie with default
|
|
|
|
options, or it can be an object of options.<p>
|
|
|
|
<p>The following example sets two cookies - one called <code>name</code> with
|
|
|
|
a value of <code>nick</code>, the other called <code>session</code> with a
|
|
|
|
value of <code>1234</code> and an expiry set to 15 minutes.</p>
|
|
|
|
<pre>
|
|
|
|
msg.cookies = {
|
|
|
|
name: 'nick',
|
|
|
|
session: {
|
|
|
|
value: '1234',
|
|
|
|
maxAge: 900000
|
|
|
|
}
|
|
|
|
}</pre>
|
|
|
|
<p>The valid options include:</p>
|
|
|
|
<ul>
|
|
|
|
<li><code>domain</code> - (String) domain name for the cookie</li>
|
|
|
|
<li><code>expires</code> - (Date) expiry date in GMT. If not specified or set to 0, creates a session cookie</li>
|
|
|
|
<li><code>maxAge</code> - (String) expiry date as relative to the current time in milliseconds</li>
|
|
|
|
<li><code>path</code> - (String) path for the cookie. Defaults to /</li>
|
|
|
|
<li><code>value</code> - (String) the value to use for the cookie</li>
|
|
|
|
</ul>
|
|
|
|
<p>To delete a cookie, set its <code>value</code> to <code>null</code>.</p>
|
|
|
|
|
2013-09-28 23:18:41 +02:00
|
|
|
</script>
|
|
|
|
|
2013-10-01 18:03:17 +02:00
|
|
|
<script type="text/javascript">
|
2017-01-24 15:56:48 +01:00
|
|
|
(function() {
|
2014-04-15 23:49:39 +02:00
|
|
|
RED.nodes.registerType('http in',{
|
|
|
|
category: 'input',
|
|
|
|
color:"rgb(231, 231, 174)",
|
|
|
|
defaults: {
|
|
|
|
name: {value:""},
|
2016-10-28 09:37:33 +02:00
|
|
|
url: {value:"",required:true},
|
2015-04-24 20:53:38 +02:00
|
|
|
method: {value:"get",required:true},
|
2017-01-16 23:39:30 +01:00
|
|
|
upload: {value:false},
|
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();
|
|
|
|
}
|
2017-01-16 23:39:30 +01:00
|
|
|
$("#node-input-method").change(function() {
|
|
|
|
if ($(this).val() === "post") {
|
|
|
|
$(".form-row-http-in-upload").show();
|
|
|
|
} else {
|
|
|
|
$(".form-row-http-in-upload").hide();
|
|
|
|
}
|
|
|
|
}).change();
|
|
|
|
|
|
|
|
|
2014-04-15 23:49:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2017-01-24 15:56:48 +01:00
|
|
|
var headerTypes = [
|
|
|
|
{value:"content-type",label:"Content-Type",hasValue: false},
|
|
|
|
{value:"location",label:"Location",hasValue: false},
|
|
|
|
{value:"other",label:"other",icon:"red/images/typedInput/az.png"}
|
|
|
|
]
|
|
|
|
var contentTypes = [
|
|
|
|
{value:"application/json",label:"application/json",hasValue: false},
|
|
|
|
{value:"application/xml",label:"application/xml",hasValue: false},
|
|
|
|
{value:"text/css",label:"text/css",hasValue: false},
|
|
|
|
{value:"text/html",label:"text/html",hasValue: false},
|
|
|
|
{value:"text/plain",label:"text/plain",hasValue: false},
|
|
|
|
{value:"image/gif",label:"image/gif",hasValue: false},
|
|
|
|
{value:"image/png",label:"image/png",hasValue: false},
|
|
|
|
{value:"other",label:"other",icon:"red/images/typedInput/az.png"}
|
|
|
|
];
|
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: {
|
2017-01-24 15:56:48 +01:00
|
|
|
name: {value:""},
|
|
|
|
statusCode: {value:"",validate: RED.validators.number(true)},
|
|
|
|
headers: {value:{}}
|
2014-04-15 23:49:39 +02:00
|
|
|
},
|
|
|
|
inputs:1,
|
|
|
|
outputs:0,
|
|
|
|
align: "right",
|
|
|
|
icon: "white-globe.png",
|
|
|
|
label: function() {
|
2017-01-24 15:56:48 +01:00
|
|
|
return this.name||("http"+(this.statusCode?" ("+this.statusCode+")":""));
|
2014-04-15 23:49:39 +02:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
2017-01-24 15:56:48 +01:00
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
function resizeRule(rule) {
|
|
|
|
var newWidth = rule.width();
|
|
|
|
rule.find('.red-ui-typedInput').typedInput("width",(newWidth-15)/2);
|
|
|
|
|
|
|
|
}
|
|
|
|
var headerList = $("#node-input-headers-container").css('min-height','150px').css('min-width','450px').editableList({
|
|
|
|
addItem: function(container,i,header) {
|
|
|
|
var row = $('<div/>').appendTo(container);
|
|
|
|
var propertyName = $('<input/>',{class:"node-input-header-name",type:"text"})
|
|
|
|
.appendTo(row)
|
|
|
|
.typedInput({types:headerTypes});
|
|
|
|
|
|
|
|
var propertyValue = $('<input/>',{class:"node-input-header-value",type:"text",style:"margin-left: 10px"})
|
|
|
|
.appendTo(row)
|
|
|
|
.typedInput({types:
|
|
|
|
header.h === 'content-type'?contentTypes:[{value:"other",label:"other",icon:"red/images/typedInput/az.png"}]
|
|
|
|
});
|
|
|
|
|
|
|
|
var matchedType = headerTypes.filter(function(ht) {
|
|
|
|
return ht.value === header.h
|
|
|
|
});
|
|
|
|
if (matchedType.length === 0) {
|
|
|
|
propertyName.typedInput('type','other');
|
|
|
|
propertyName.typedInput('value',header.h);
|
|
|
|
propertyValue.typedInput('value',header.v);
|
|
|
|
} else {
|
|
|
|
propertyName.typedInput('type',header.h);
|
|
|
|
|
|
|
|
if (header.h === "content-type") {
|
|
|
|
matchedType = contentTypes.filter(function(ct) {
|
|
|
|
return ct.value === header.v;
|
|
|
|
});
|
|
|
|
if (matchedType.length === 0) {
|
|
|
|
propertyValue.typedInput('type','other');
|
|
|
|
propertyValue.typedInput('value',header.v);
|
|
|
|
} else {
|
|
|
|
propertyValue.typedInput('type',header.v);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
propertyValue.typedInput('value',header.v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
matchedType = headerTypes.filter(function(ht) {
|
|
|
|
return ht.value === header.h
|
|
|
|
});
|
|
|
|
if (matchedType.length === 0) {
|
|
|
|
propertyName.typedInput('type','other');
|
|
|
|
propertyName.typedInput('value',header.h);
|
|
|
|
} else {
|
|
|
|
propertyName.typedInput('type',header.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
propertyName.on('change',function(event) {
|
|
|
|
var type = propertyName.typedInput('type');
|
|
|
|
if (type === 'content-type') {
|
|
|
|
propertyValue.typedInput('types',contentTypes);
|
|
|
|
} else {
|
|
|
|
propertyValue.typedInput('types',[{value:"other",label:"other",icon:"red/images/typedInput/az.png"}]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resizeRule(container);
|
|
|
|
},
|
|
|
|
resizeItem: resizeRule,
|
|
|
|
removable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.headers) {
|
|
|
|
for (var key in this.headers) {
|
|
|
|
if (this.headers.hasOwnProperty(key)) {
|
|
|
|
headerList.editableList('addItem',{h:key,v:this.headers[key]});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oneditsave: function() {
|
|
|
|
var headers = $("#node-input-headers-container").editableList('items');
|
|
|
|
var node = this;
|
|
|
|
node.headers = {};
|
|
|
|
headers.each(function(i) {
|
|
|
|
var header = $(this);
|
|
|
|
var keyType = header.find(".node-input-header-name").typedInput('type');
|
|
|
|
var keyValue = header.find(".node-input-header-name").typedInput('value');
|
|
|
|
var valueType = header.find(".node-input-header-value").typedInput('type');
|
|
|
|
var valueValue = header.find(".node-input-header-value").typedInput('value');
|
|
|
|
var key = keyType;
|
|
|
|
var value = valueType;
|
|
|
|
if (keyType === 'other') {
|
|
|
|
key = keyValue;
|
|
|
|
}
|
|
|
|
if (valueType === 'other') {
|
|
|
|
value = valueValue;
|
|
|
|
}
|
|
|
|
if (key !== '') {
|
|
|
|
node.headers[key] = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
oneditresize: function(size) {
|
|
|
|
var rows = $("#dialog-form>div:not(.node-input-headers-container-row)");
|
|
|
|
var height = size.height;
|
|
|
|
for (var i=0; i<rows.size(); i++) {
|
|
|
|
height -= $(rows[i]).outerHeight(true);
|
|
|
|
}
|
|
|
|
var editorRow = $("#dialog-form>div.node-input-headers-container-row");
|
|
|
|
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
|
|
|
|
|
|
|
$("#node-input-headers-container").editableList('height',height);
|
2014-04-15 23:49:39 +02:00
|
|
|
}
|
|
|
|
});
|
2017-01-24 15:56:48 +01:00
|
|
|
})();
|
2013-09-05 16:02:48 +02:00
|
|
|
</script>
|