mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add HTTP Response node to make http flows easier to handle
This commit is contained in:
parent
6341c2e907
commit
68e7e5e226
@ -50,13 +50,14 @@
|
||||
<pre>foo=bar&this=that</pre>
|
||||
</p>
|
||||
<p>
|
||||
To send JSON encoded data, the content-type header of the request must be set to
|
||||
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 must be done within
|
||||
a subsequent Function node. The <a href="http://expressjs.com/api.html#res">Express response documentation</a>
|
||||
describes how this should be done.
|
||||
<b>Note: </b>This node does not send any response to the http request. This should be done with
|
||||
a subsequent HTTP Response node, or Function node.
|
||||
In the case of a Function node, the <a href="http://expressjs.com/api.html#res">Express response documentation</a>
|
||||
describes how this should be done. For example:
|
||||
<pre>msg.res.send(200, 'Thanks for the request ');<br/>return msg;</pre>
|
||||
</p>
|
||||
|
||||
@ -81,5 +82,37 @@
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="http response">
|
||||
<div class="form-tips">The messages sent to this node must originate from an HTTP input node</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="http response">
|
||||
<p>Provides an response node for http requests received from an http input node.</p>
|
||||
<ul>
|
||||
<li><code>payload</code> is sent as the body of the reponse</li>
|
||||
<li><code>rc</code>, if set, is used as the response 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>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('http response',{
|
||||
category: 'output',
|
||||
color:"rgb(231, 231, 174)",
|
||||
defaults: {},
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
align: "right",
|
||||
icon: "white-globe.png",
|
||||
label: function() {
|
||||
return "http"
|
||||
},
|
||||
labelStyle: function() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -35,11 +35,8 @@ function HTTPIn(n) {
|
||||
} else if (this.method == "delete") {
|
||||
RED.app.delete(this.url,this.callback);
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http in",HTTPIn);
|
||||
|
||||
HTTPIn.prototype.close = function() {
|
||||
this.on("close",function() {
|
||||
var routes = RED.app.routes[this.method];
|
||||
for (var i in routes) {
|
||||
if (routes[i].path == this.url) {
|
||||
@ -47,5 +44,24 @@ HTTPIn.prototype.close = function() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http in",HTTPIn);
|
||||
|
||||
|
||||
function HTTPOut(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
this.on("input",function(msg) {
|
||||
if (msg.res) {
|
||||
if (msg.headers) {
|
||||
res.set(msg.headers);
|
||||
}
|
||||
var rc = msg.rc || 200;
|
||||
msg.res.send(rc,msg.payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http response",HTTPOut);
|
||||
|
Loading…
Reference in New Issue
Block a user