Skip to main content

Node http request

The http request node is designed to perform HTTP requests to external web services or APIs. It supports multiple HTTP methods, data transmission methods, authentication, and flexible management of requests and responses.


Settings for the http request node

IMG2

1. Name

A field for specifying the name of the node.
The name is displayed in the workspace and helps easily identify the node.
If left empty, the node will be called http request.

Example:

  • Node name: Get Weather Data

2. Method

The HTTP method that will be used for the request. The choice of method depends on the type of operation that needs to be performed.

Available methods:

  • GET: Retrieve data.
  • POST: Send data.
  • PUT: Update data.
  • DELETE: Delete data.
  • HEAD: Retrieve response headers.

Example:

  • Method: POST

A field for specifying a static URL to which the request will be sent.
If the address needs to be set dynamically, it can be passed in msg.url.

Example:

  • Link: https://api.example.com/data

4. Data

Defines how the input data will be added to the HTTP request. The following options are available:

  1. Ignore (default):
    Input data will not be used in the request. The msg.payload field, if it exists, will be ignored.

    Example:
    If msg.payload contains a JSON object, it will not be included in the request.


  1. Add to query parameters:
    Data from msg.payload will be converted into query parameters and added to the URL.

    Example:
    If msg.payload contains:

    {
    "key1": "value1",
    "key2": "value2"
    }

    If Link is specified as http://example.com/api, the final request will be:
    GET http://example.com/api?key1=value1&key2=value2.


  1. Send as request body:
    Data from msg.payload will be sent in the body of the request. This option is suitable for POST and PUT methods, where data is often sent in the body.

    Example:
    If msg.payload contains:

    {
    "name": "John Doe",
    "email": "john.doe@example.com"
    }

    If the request method is POST, the data will be sent in the body of the request with the appropriate content.

5. Return

Defines the format in which the node will process the response from the server.

Options:

  • String: The response is converted to a string (default).
  • Object JSON: If the server response is in JSON format, it is automatically converted to a JavaScript object.
  • Binary Buffer: The response is returned as a binary buffer (useful for binary data such as images or files).

Example:

  • If Object JSON is selected, the response:
    {"status": "ok", "value": 42}
    is converted to:
    msg.payload = { status: "ok", value: 42 };

6. Use Authentication

A checkbox that enables built-in authentication (default is off). When enabled, a Type field appears in the form with the authentication method (default is basic):

basic

  • Username: Username.
  • Password: Password.

bearer

  • Password: Access token.

digest

  • Username: Username.
  • Password: Password.

Input Data

The http request node accepts a message object msg with the following parameters:

  1. msg.url: URL for the request (if not specified in the node settings).
  2. msg.method: HTTP method (if not specified in the node settings).
  3. msg.payload: Body of the request (used for POST, PUT methods).
  4. msg.headers: HTTP request headers (object).

Output Data

The node returns a msg object with information about the executed request:

  1. msg.payload: Data from the server response.
  2. msg.statusCode: HTTP status code of the response (e.g., 200 or 404).
  3. msg.headers: Response headers.
  4. msg.responseUrl: URL to which the request was made.
  5. msg.error: Description of the error (if the request failed).

Usage Examples

Example 1: Performing a GET request

Node settings:

  • Method: GET
  • Link: https://api.weatherapi.com/v1/current.json?key=API_KEY&q=London

Flow:

[inject] ---> [http request] ---> [debug]

Result: The node will return JSON with the current weather.


Example 2: Sending data via POST

Node settings:

  • Method: POST
  • Link: https://api.example.com/devices
  • Data: Send as request body

Flow:

[function] ---> [http request] ---> [debug]

Code in the function node:

msg.payload = {
deviceId: "sensor123",
status: "active"
};
msg.headers = { "Content-Type": "application/json" };
return msg;

Result: The data will be sent, and the node will return the server's response.


Example 3: Dynamic URL and authentication

Node settings:

  • Link: (leave empty)

Flow:

[function] ---> [http request] ---> [debug]

Code in the function node:

msg.url = "https://api.example.com/user/123";
msg.headers = { Authorization: "Bearer YOUR_TOKEN" };
return msg;

Result: The node will make a request to the specified URL with the authentication token.