# How to handle multiple http post request at once

**URL:** <https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248>\
**Category:** General\
**Created:** [2 July 2018 21:47 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248 "2018-07-02T21:47:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergiogama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sergiogama/32/357_2.png) [@sergiogama](https://discourse.nodered.org/u/sergiogama)\
**Post date:** [2 July 2018 21:47 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/1 "2018-07-02T21:47:48Z")

</div>

Hi all,

I have a flow which has a http end point (Post), that process something in the middle and send response thru http response. The problem is that the client system make many calls in one shot (node.js, using Promisse.all), and my flow receive every calls, respond one of them the others crash with the message that the headers has been already used.  
Question: How control this queue and process each call without error on http response?

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [2 July 2018 22:30 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/2 "2018-07-02T22:30:39Z")

</div>

I have no idea… but what happens if you save all the request on a buffer and release one request at time with some delay between each release in order to be able to handle the response prior to process next request?

As example if you use the rate limit x messages per x seconds will do the job.`maybe…

```auto
[{"id":"6bd57f39.c0d1c","type":"debug","z":"b7eb5457.b00758","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":524,"y":1343,"wires":[]},{"id":"a9f98f83.55d8","type":"inject","z":"b7eb5457.b00758","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":128,"y":1328,"wires":[["2527d6b0.9117ca"]]},{"id":"2527d6b0.9117ca","type":"delay","z":"b7eb5457.b00758","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":327,"y":1335,"wires":[["6bd57f39.c0d1c"]]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 July 2018 22:32 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/3 "2018-07-02T22:32:50Z")

</div>

That sounds like a msg.res object is being reused.

Can you share your flow so we can see what you’re doing with the msgs between the http in and response nodes?

---

<div class="post-metadata">

**Author:** ![sergiogama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sergiogama/32/357_2.png) [@sergiogama](https://discourse.nodered.org/u/sergiogama)\
**Post date:** [3 July 2018 06:05 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/4 "2018-07-03T06:05:27Z")

</div>

Yes, sure…

```auto
[{"id":"b3369f6.48b956","type":"http in","z":"89fa1dea.67dd2","name":"","url":"/classifica","method":"post","upload":false,"swaggerDoc":"","x":100,"y":60,"wires":[["bb4bf78d.633a18"]],"icon":"node-red/subflow.png"},{"id":"bb4bf78d.633a18","type":"change","z":"89fa1dea.67dd2","name":"","rules":[{"t":"set","p":"pageIndex","pt":"flow","to":"req.body.pageIndex","tot":"msg"},{"t":"set","p":"pageName","pt":"flow","to":"req.body.pageName","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"req.body.ocrData","tot":"msg"},{"t":"set","p":"resAux","pt":"flow","to":"res","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":285,"y":60,"wires":[["92a409da.19bed8","4dc50b49.d997a4"]]},{"id":"92a409da.19bed8","type":"debug","z":"89fa1dea.67dd2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":830,"y":60,"wires":[]},{"id":"46c28d10.c2daf4","type":"http response","z":"89fa1dea.67dd2","name":"","statusCode":"","headers":{},"x":845,"y":361,"wires":[],"icon":"node-red/subflow.png"},{"id":"983540d4.2676","type":"natural-language-understanding","z":"89fa1dea.67dd2","name":"","categories":false,"concepts":false,"maxconcepts":"8","doc-emotion":false,"doc-emotion-target":"","doc-sentiment":false,"doc-sentiment-target":"","entity":true,"entity-emotion":false,"entity-sentiment":false,"maxentities":"50","keyword":false,"keyword-emotion":false,"keyword-sentiment":false,"maxkeywords":"50","metadata":false,"relation":true,"semantic":false,"semantic-entities":false,"semantic-keywords":false,"maxsemantics":"50","default-endpoint":true,"service-endpoint":"https://gateway.watsonplatform.net/natural-language-understanding/api","x":600,"y":222,"wires":[["93679d2e.6353f","23ca5b8a.154c24"]]},{"id":"c89b6732.bd3f68","type":"function","z":"89fa1dea.67dd2","name":"Peticoes","func":"msg = \n{nlu_options:{entity_model:\"10:091feb70-50d5-40a1-8513-3d5b4d687c6b\",\n relations_model:\"10:091feb70-50d5-40a1-8513-3d5b4d687c6b\"\n},\n payload:msg.payload,\n res:msg.res,\n req:msg.req\n};\nreturn msg;","outputs":1,"noerr":0,"x":269,"y":147,"wires":[["983540d4.2676"]]},{"id":"93679d2e.6353f","type":"debug","z":"89fa1dea.67dd2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":830,"y":142,"wires":[]},{"id":"4dc50b49.d997a4","type":"switch","z":"89fa1dea.67dd2","name":"Modelos","property":"pageIndex","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"4","vt":"str"},{"t":"eq","v":"5","vt":"str"},{"t":"eq","v":"7","vt":"str"},{"t":"eq","v":"6","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":8,"x":105,"y":193,"wires":[["c89b6732.bd3f68"],["e5249163.e3101"],["e5249163.e3101"],["4309848c.6ff76c"],["6218147c.3b7eac"],["64a2dc3b.916984"],["c9f3fe53.70eb1"],["61702483.62761c"]]},{"id":"d0790050.5eb09","type":"comment","z":"89fa1dea.67dd2","name":"Modelos","info":"{pageIndex: 1, pageName: 'Petição'},\n{pageIndex: 2, pageName: 'Guia'},\n{pageIndex: 3, pageName: 'Guia'},\n{pageIndex: 4, pageName: 'Comprovante'},\n{pageIndex: 5, pageName: 'Determinação Judicial'},\n{pageIndex: 6, pageName: 'Print TJ'},\n{pageIndex: 7, pageName: 'Correio'}","x":109,"y":280,"wires":[]},{"id":"e5249163.e3101","type":"function","z":"89fa1dea.67dd2","name":"Guia","func":"msg = \n{nlu_options:{entity_model:\"10:130a669d-13b5-47fa-af7b-c694e4b695a6\",\n relations_model:\"10:130a669d-13b5-47fa-af7b-c694e4b695a6\"\n},\n payload:msg.payload,\n res:msg.res,\n req:msg.req\n};\nreturn msg;","outputs":1,"noerr":0,"x":259,"y":183,"wires":[["983540d4.2676"]]},{"id":"4309848c.6ff76c","type":"function","z":"89fa1dea.67dd2","name":"Comprovante","func":"msg = \n{nlu_options:{entity_model:\"10:d6e6adad-c89b-4f27-856b-52ef9d97eca8\",\n relations_model:\"10:d6e6adad-c89b-4f27-856b-52ef9d97eca8\"\n},\n payload:msg.payload,\n res:msg.res,\n req:msg.req\n};\nreturn msg;","outputs":1,"noerr":0,"x":289,"y":219,"wires":[["983540d4.2676"]]},{"id":"c9f3fe53.70eb1","type":"function","z":"89fa1dea.67dd2","name":"Correio","func":"msg = \n{nlu_options:{entity_model:\"10:d6e8bc64-ccbb-436f-a488-dfc5ea5b1a9d\",\n relations_model:\"10:d6e8bc64-ccbb-436f-a488-dfc5ea5b1a9d\"\n},\n payload:msg.payload,\n res:msg.res,\n req:msg.req\n};\nreturn msg;","outputs":1,"noerr":0,"x":269,"y":327,"wires":[["983540d4.2676"]]},{"id":"64a2dc3b.916984","type":"function","z":"89fa1dea.67dd2","name":"Print_TJ","func":"msg = \n{nlu_options:{entity_model:\"10:560e1396-ea4d-48e4-84ae-d801786ebd14\",\n relations_model:\"10:560e1396-ea4d-48e4-84ae-d801786ebd14\"\n},\n payload:msg.payload,\n res:msg.res,\n req:msg.req\n};\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":291,"wires":[["983540d4.2676"]]},{"id":"6218147c.3b7eac","type":"function","z":"89fa1dea.67dd2","name":"Determinação Judicial","func":"msg = \n{nlu_options:{entity_model:\"10:091feb70-50d5-40a1-8513-3d5b4d687c6b\",\n relations_model:\"10:091feb70-50d5-40a1-8513-3d5b4d687c6b\"\n},\n payload:msg.payload,\n res:msg.res,\n req:msg.req\n};\nreturn msg;","outputs":1,"noerr":0,"x":309,"y":254,"wires":[["bb53018d.70c0c"]]},{"id":"61702483.62761c","type":"function","z":"89fa1dea.67dd2","name":"Modelo Inexistente","func":"msg.payload =\n{\"rc\":300,\"msg\":\"Modelo desconhecido\"};\nreturn msg;","outputs":1,"noerr":0,"x":299,"y":363,"wires":[["1e755ac.5d36ea5"]]},{"id":"bb53018d.70c0c","type":"function","z":"89fa1dea.67dd2","name":"","func":"msg.payload = \n{\"rc\":350,\"msg\":\"Modelo em construção\"};\nreturn msg;","outputs":1,"noerr":0,"x":495,"y":322,"wires":[["1e755ac.5d36ea5"]]},{"id":"23ca5b8a.154c24","type":"change","z":"89fa1dea.67dd2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"features","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":637,"y":280,"wires":[["1e755ac.5d36ea5"]]},{"id":"7d595d5.1f022a4","type":"catch","z":"89fa1dea.67dd2","name":"","scope":["983540d4.2676"],"x":259,"y":442,"wires":[["9be9b90b.d98348","7a750f77.fcadb"]]},{"id":"7a750f77.fcadb","type":"debug","z":"89fa1dea.67dd2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":710,"y":522,"wires":[]},{"id":"9be9b90b.d98348","type":"function","z":"89fa1dea.67dd2","name":"","func":"msg.payload = \n{\"rc\":360,\"msg\":\"Erro inesperado no NLU\"};\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":442,"wires":[["1e755ac.5d36ea5"]]},{"id":"1e755ac.5d36ea5","type":"change","z":"89fa1dea.67dd2","name":"","rules":[{"t":"set","p":"res","pt":"msg","to":"resAux","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":646,"y":361,"wires":[["46c28d10.c2daf4","9d9ba5fb.2e1918"]]},{"id":"d4d88658.0dbcf8","type":"cloudant out","z":"89fa1dea.67dd2","name":"","cloudant":"","database":"dokia","service":"node-red-dokia-cloudantNoSQLDB","payonly":false,"operation":"insert","x":844.5,"y":456,"wires":[]},{"id":"e2e40381.8767d","type":"function","z":"89fa1dea.67dd2","name":"","func":"msg = \n{pageIndex:context.flow.pageIndex,\n pageName:context.flow.pageName,\n ocrData:context.flow.ocrData,\n NLU:msg.features};\nreturn msg;","outputs":1,"noerr":0,"x":703.5,"y":456,"wires":[["d4d88658.0dbcf8"]]},{"id":"9d9ba5fb.2e1918","type":"delay","z":"89fa1dea.67dd2","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":700.5,"y":411,"wires":[["e2e40381.8767d"]]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [3 July 2018 08:08 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/5 "2018-07-03T08:08:49Z")

</div>

@sergiogama the first Change node in your flow is copying `msg.res` to `flow.resAux` - which you then copy back at the end of your flow.

That is the cause of the problem. As soon as the second request arrives, whilst the first is still being processed, `flow.resAux` will be overwritten with the response object for the second request. When the first request reaches the final Change node, it will be given the second request’s response object - and respond to the wrong request.

The same will be true of `flow.pageName` and `flow.pageIndex` which you also set each time a message arrives.

You need to leave `msg.res` attached to the message as it passes through the whole flow.

---

<div class="post-metadata">

**Author:** ![sergiogama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sergiogama/32/357_2.png) [@sergiogama](https://discourse.nodered.org/u/sergiogama)\
**Post date:** [3 July 2018 18:20 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/6 "2018-07-03T18:20:35Z")

</div>

Thanks!! I will try!!

---

<div class="post-metadata">

**Author:** ![sergiogama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sergiogama/32/357_2.png) [@sergiogama](https://discourse.nodered.org/u/sergiogama)\
**Post date:** [4 July 2018 13:24 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/7 "2018-07-04T13:24:22Z")

</div>

Thanks! It’s woking fine!!

---

<div class="post-metadata">

**Author:** ![EyyupAlkis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eyyupalkis/32/10695_2.png) [@EyyupAlkis](https://discourse.nodered.org/u/EyyupAlkis)\
**Post date:** [8 March 2019 08:14 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/8 "2019-03-08T08:14:55Z")

</div>

Is there any limitation of request on node-red server ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 March 2019 08:45 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/9 "2019-03-08T08:45:01Z")

</div>

In what way do you mean?

---

<div class="post-metadata">

**Author:** ![EyyupAlkis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eyyupalkis/32/10695_2.png) [@EyyupAlkis](https://discourse.nodered.org/u/EyyupAlkis)\
**Post date:** [18 March 2019 14:08 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/10 "2019-03-18T14:08:37Z")

</div>

![ss](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b05d0e325d1d6fe18077d288f61ae610a2c80f50.png) ![ss2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/be3f381999392389d9e4b4cd421681ad7d87297f.png)

For example I have multinodes like above and much more which handle multiple mqtt process and http requests. And sensors which are in my house send data to node-red asynchronously. Can Node-red handle it at the same time or I should try different approaches ? I am new on red sorry for my ignorance and thanks for answering

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 March 2019 14:24 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/11 "2019-03-18T14:24:25Z")

</div>

It should handle it unless you run or processor power or (if you are doing a lot of web stuff) network bandwith. So it depends on what hardware you are using. However, a Pi, for example, will likely handle hundreds of requests a second before it runs out of steam.

---

<div class="post-metadata">

**Author:** ![EyyupAlkis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eyyupalkis/32/10695_2.png) [@EyyupAlkis](https://discourse.nodered.org/u/EyyupAlkis)\
**Post date:** [18 March 2019 14:29 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/12 "2019-03-18T14:29:17Z")

</div>

thanks for answering 🙂 and the last question, all nodes use msg.payload, is this msg object same for each thread or different ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 March 2019 14:34 UTC](https://discourse.nodered.org/t/how-to-handle-multiple-http-post-request-at-once/1248/13 "2019-03-18T14:34:17Z")

</div>

Messages are passed down the wires between nodes so they will all be different.  
Read through the docs, particularly the user guide, to see how the system works  
[https://nodered.org/docs](https://nodered.org/docs)
