mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			184 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!--
 | 
						|
  Copyright 2013, 2016 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">
 | 
						|
        <label for="node-input-method"><i class="fa fa-tasks"></i> <span data-i18n="httpin.label.method"></span></label>
 | 
						|
        <select type="text" id="node-input-method" style="width:72%;">
 | 
						|
        <option value="get">GET</option>
 | 
						|
        <option value="post">POST</option>
 | 
						|
        <option value="put">PUT</option>
 | 
						|
        <option value="delete">DELETE</option>
 | 
						|
        <option value="patch">PATCH</option>
 | 
						|
        </select>
 | 
						|
    </div>
 | 
						|
    <div class="form-row">
 | 
						|
        <label for="node-input-url"><i class="fa fa-globe"></i> <span data-i18n="httpin.label.url"></span></label>
 | 
						|
        <input type="text" id="node-input-url" placeholder="/url">
 | 
						|
    </div>
 | 
						|
    <div class="form-row">
 | 
						|
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
 | 
						|
        <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
 | 
						|
    </div>
 | 
						|
    <div class="form-row row-swagger-doc">
 | 
						|
        <label for="node-input-swaggerDoc"><i class="fa fa-file-text-o"></i> <span data-i18n="httpin.label.doc"></span></label>
 | 
						|
        <input type="text" id="node-input-swaggerDoc">
 | 
						|
    </div>
 | 
						|
    <div id="node-input-tip" class="form-tips"><span data-i18n="httpin.tip.in"></span><code><span id="node-input-path"></span></code>.</div>
 | 
						|
</script>
 | 
						|
 | 
						|
<script type="text/x-red" data-help-name="http in">
 | 
						|
    <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>
 | 
						|
    </p>
 | 
						|
    <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.
 | 
						|
    </p>
 | 
						|
    <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>
 | 
						|
       <b>Note: </b>This node does not send any response to the http request.
 | 
						|
       This should be done with a subsequent HTTP Response node.
 | 
						|
    </p>
 | 
						|
 | 
						|
</script>
 | 
						|
 | 
						|
<script type="text/x-red" data-template-name="http response">
 | 
						|
    <div class="form-row">
 | 
						|
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
 | 
						|
        <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
 | 
						|
    </div>
 | 
						|
    <div class="form-tips"><span data-i18n="[html]httpin.tip.res"></span></div>
 | 
						|
</script>
 | 
						|
 | 
						|
<script type="text/x-red" data-help-name="http response">
 | 
						|
    <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>
 | 
						|
        <li><code>payload</code> is sent as the body of the response</li>
 | 
						|
        <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>
 | 
						|
        <li><code>cookies</code>, if set, can be used to set or delete cookies.
 | 
						|
    </ul>
 | 
						|
    <h3>Cookie handling</h3>
 | 
						|
    <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>
 | 
						|
 | 
						|
</script>
 | 
						|
 | 
						|
<script type="text/javascript">
 | 
						|
    RED.nodes.registerType('http in',{
 | 
						|
        category: 'input',
 | 
						|
        color:"rgb(231, 231, 174)",
 | 
						|
        defaults: {
 | 
						|
            name: {value:""},
 | 
						|
            url: {value:"",required:true},
 | 
						|
            method: {value:"get",required:true},
 | 
						|
            swaggerDoc: {type:"swagger-doc", required:false}
 | 
						|
        },
 | 
						|
        inputs:0,
 | 
						|
        outputs:1,
 | 
						|
        icon: "white-globe.png",
 | 
						|
        label: function() {
 | 
						|
            if (this.name) {
 | 
						|
                return this.name;
 | 
						|
            } else if (this.url) {
 | 
						|
                var root = RED.settings.httpNodeRoot;
 | 
						|
                if (root.slice(-1) != "/") {
 | 
						|
                    root = root+"/";
 | 
						|
                }
 | 
						|
                if (this.url.charAt(0) == "/") {
 | 
						|
                    root += this.url.slice(1);
 | 
						|
                } else {
 | 
						|
                    root += this.url;
 | 
						|
                }
 | 
						|
                return "["+this.method+"] "+root;
 | 
						|
            } else {
 | 
						|
                return "http";
 | 
						|
            }
 | 
						|
        },
 | 
						|
        labelStyle: function() {
 | 
						|
            return this.name?"node_label_italic":"";
 | 
						|
        },
 | 
						|
        oneditprepare: function() {
 | 
						|
            var root = RED.settings.httpNodeRoot;
 | 
						|
            if (root.slice(-1) == "/") {
 | 
						|
                root = root.slice(0,-1);
 | 
						|
            }
 | 
						|
            if (root == "") {
 | 
						|
                $("#node-input-tip").hide();
 | 
						|
            } else {
 | 
						|
                $("#node-input-path").html(root);
 | 
						|
                $("#node-input-tip").show();
 | 
						|
            }
 | 
						|
            if(!RED.nodes.getType("swagger-doc")){
 | 
						|
                $('.row-swagger-doc').hide();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
    });
 | 
						|
 | 
						|
    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":"";
 | 
						|
        }
 | 
						|
    });
 | 
						|
</script>
 |