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 types, authentication, and flexible management of requests and responses.


Settings for the http request node

IMG2

1. Name

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.
  • PATCH: Partially update data.
  • HEAD: Retrieve response headers.
  • OPTIONS: Get information about the API.

Example:

  • Method: POST

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:
    The input data will not be used in the request. The msg.payload, 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 methods such as POST, PUT, and PATCH, 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:

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

Example:

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

6. Authentication

The node supports built-in authentication mechanisms.

Basic Auth

  • Username: Username.
  • Password: Password.

Bearer Token

  • Token: Access token.

Digest

  • Username: Username.
  • Password: Password.

Input

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, PATCH methods).
  4. msg.headers: HTTP request headers (object).

Output

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

  1. msg.payload: Response data from the server.
  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: Error description (if the request failed).

Usage Examples

Example 1: Performing a GET request

Node settings:

  • Method: GET
  • URL: 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
  • URL: https://api.example.com/devices
  • Data: JSON

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:

  • URL: (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.