HTTP requests example

http requests

This is tutorial project displaying how to make and recieve HTTP requests in Node-RED.

List of used nodes

  • Inject/Timestamp – Triggers flow execution

  • Function – Adds custom logic using JavaScript

  • HTTP Request – Sends HTTP requests to external services

  • Debug – Displays messages in the debug console

  • JSON - parse JSON to JS object

  • HTTP in - recieve HTTP requests

  • HTTP response - respond to HTTP requests

For details, see Node-RED Documentation

GROUP: send HTTP request

group http send request

This group has two demo flows that show how to set up the HTTP request node.

  • Runtime config (shown below): a Function node sets msg.url, msg.method, and msg.headers on the fly—handy when they may vary.

  • Static config: enter the same fields in the node’s edit dialog if they never change.

FLOW: Runtime config

Press the Inject button to fire the flow. The Function node builds the call:

// POST /api/post-example with a JSON body
msg.method  = "POST";
msg.url     = "http://127.0.0.1:1880/api/post-example";
msg.headers = { "Content-Type": "application/json" };
msg.payload = { message: "hello world" };
return msg;

All settings are passed in the msg object; the JSON body sits in msg.payload.

FLOW: Static config

gui http request node

This example uses the node’s GUI for a static setup. Method and URL are locked in before deployment and can’t be altered at runtime. If the request type supports a body (e.g., POST, PUT), put the content in msg.payload; for body-less verbs (e.g., GET, DELETE), leave payload empty to prevent errors and configure Payload dropdown to Ignore.

GROUP: handle response

group handle response

This group handles replies to the previous group’s HTTP calls. An HTTP in node receives the request, a Debug node logs it, and an HTTP response node returns the status code and body to the caller.