2 Copyright 2013 IBM Corp.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 <script type="text/x-red" data-template-name="http in">
18 <div class="form-row">
19 <label for="node-input-method"><i class="fa fa-tasks"></i> Method</label>
20 <select type="text" id="node-input-method" style="width:72%;">
21 <option value="get">GET</option>
22 <option value="post">POST</option>
23 <option value="put">PUT</option>
24 <option value="delete">DELETE</option>
27 <div class="form-row">
28 <label for="node-input-url"><i class="fa fa-globe"></i> url</label>
29 <input type="text" id="node-input-url" placeholder="/url">
31 <div class="form-row">
32 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
33 <input type="text" id="node-input-name" placeholder="Name">
35 <div id="node-input-tip" class="form-tips">The url will be relative to <code><span id="node-input-path"></span></code>.</div>
38 <script type="text/x-red" data-help-name="http in">
39 <p>Provides an input node for http requests, allowing the creation of simple web services.</p>
40 <p>The resulting message has the following properties:
42 <li>msg.req : <a href="http://expressjs.com/api.html#req">http request</a></li>
43 <li>msg.res : <a href="http://expressjs.com/api.html#res">http response</a></li>
46 <p>For POST/PUT requests, the body is available under <code>msg.req.body</code>. This
47 uses the <a href="http://expressjs.com/api.html#bodyParser">Express bodyParser middleware</a> to parse the content to a JSON object.
50 By default, this expects the body of the request to be url encoded:
51 <pre>foo=bar&this=that</pre>
54 To send JSON encoded data to the node, the content-type header of the request must be set to
55 <code>application/json</code>.
58 <b>Note: </b>This node does not send any response to the http request. This should be done with
59 a subsequent HTTP Response node, or Function node.
60 In the case of a Function node, the <a href="http://expressjs.com/api.html#res">Express response documentation</a>
61 describes how this should be done. For example:
62 <pre>msg.res.send(200, 'Thanks for the request ');<br/>return msg;</pre>
67 <script type="text/x-red" data-template-name="http response">
68 <div class="form-row">
69 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
70 <input type="text" id="node-input-name" placeholder="Name">
72 <div class="form-tips">The messages sent to this node <b>must</b> originate from an <i>http input</i> node</div>
75 <script type="text/x-red" data-help-name="http response">
76 <p>Sends responses back to http requests received from an HTTP Input node.</p>
77 <p>The response can be customised using the following message properties:</p>
79 <li><code>payload</code> is sent as the body of the response</li>
80 <li><code>statusCode</code>, if set, is used as the response status code (default: 200)</li>
81 <li><code>headers</code>, if set, should be an object containing field/value
82 pairs to be added as response headers.</li>
86 <script type="text/x-red" data-template-name="http request">
87 <div class="form-row">
88 <label for="node-input-method"><i class="fa fa-tasks"></i> Method</label>
89 <select type="text" id="node-input-method" style="width:72%;">
90 <option value="GET">GET</option>
91 <option value="POST">POST</option>
92 <option value="PUT">PUT</option>
93 <option value="DELETE">DELETE</option>
96 <div class="form-row">
97 <label for="node-input-url"><i class="fa fa-globe"></i> URL</label>
98 <input type="text" id="node-input-url" placeholder="http://">
100 <div class="form-row">
101 <label> </label>
102 <input type="checkbox" id="node-input-useAuth" style="display: inline-block; width: auto; vertical-align: top;">
103 <label for="node-input-useAuth" style="width: 70%;">Use basic authentication?</label>
105 <div class="form-row node-input-useAuth-row">
106 <label for="node-input-user"><i class="fa fa-user"></i> Username</label>
107 <input type="text" id="node-input-user">
109 <div class="form-row node-input-useAuth-row">
110 <label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
111 <input type="password" id="node-input-password">
113 <div class="form-row">
114 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
115 <input type="text" id="node-input-name" placeholder="Name">
119 <script type="text/x-red" data-help-name="http request">
120 <p>Provides a node for making http requests.</p>
121 <p>The URL and HTTP method can be configured in the node, but also
122 overridden by the incoming message:
124 <li><code>url</code>, if set, is used as the url of the request. Must start with http: or https:</li>
125 <li><code>method</code>, if set, is used as the HTTP method of the request.
126 Must be one of <code>GET</code>, <code>PUT</code>, <code>POST</code> or <code>DELETE</code> (default: GET)</li>
127 <li><code>headers</code>, if set, should be an object containing field/value
128 pairs to be added as request headers</li>
129 <li><code>payload</code> is sent as the body of the request</li>
131 <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
132 url to be constructed using values of the incoming message. For example, if the url is set to
133 <code>example.com/{{topic}}</code>, it will have the value of <code>msg.topic</code> automatically inserted.</p>
135 The output message contains the following properties:
137 <li><code>payload</code> is the body of the response</li>
138 <li><code>statusCode</code> is the status code of the response, or the error code if the request could not be completed</li>
139 <li><code>headers</code> is an object containing the response headers</li>
143 <script type="text/javascript">
144 RED.nodes.registerType('http in',{
146 color:"rgb(231, 231, 174)",
149 url: {value:"",required:true},
150 method: {value:"get",required:true}
154 icon: "white-globe.png",
158 } else if (this.url) {
159 var root = RED.settings.httpNodeRoot;
160 if (root.slice(-1) != "/") {
163 if (this.url.charAt(0) == "/") {
164 root += this.url.slice(1);
168 return "["+this.method+"] "+root;
173 labelStyle: function() {
174 return this.name?"node_label_italic":"";
176 oneditprepare: function() {
177 var root = RED.settings.httpNodeRoot;
178 if (root.slice(-1) == "/") {
179 root = root.slice(0,-1);
182 $("#node-input-tip").hide();
184 $("#node-input-path").html(root);
185 $("#node-input-tip").show();
187 //document.getElementById("node-config-wsdocpath").innerHTML=
192 RED.nodes.registerType('http response',{
194 color:"rgb(231, 231, 174)",
201 icon: "white-globe.png",
203 return this.name||"http";
205 labelStyle: function() {
206 return this.name?"node_label_italic":"";
210 RED.nodes.registerType('http request',{
211 category: 'function',
212 color:"rgb(231, 231, 174)",
215 method:{value:"GET"},
217 //user -> credentials
218 //pass -> credentials
222 password: {type: "password"}
227 icon: "white-globe.png",
229 return this.name||"http request";
231 labelStyle: function() {
232 return this.name?"node_label_italic":"";
234 oneditprepare: function() {
235 if (this.credentials.user || this.credentials.has_password) {
236 $('#node-input-useAuth').prop('checked', true);
237 $(".node-input-useAuth-row").show();
239 $('#node-input-useAuth').prop('checked', false);
240 $(".node-input-useAuth-row").hide();
243 $("#node-input-useAuth").change(function() {
244 if ($(this).is(":checked")) {
245 $(".node-input-useAuth-row").show();
247 $(".node-input-useAuth-row").hide();
248 $('#node-input-user').val('');
249 $('#node-input-password').val('');