HTTP in
# What are Http-in nodes used for in Node-RED
The "HTTP In" node in Node-RED is a core node that allows you to create an HTTP endpoint within your flow. It essentially sets up an HTTP server that listens for incoming HTTP requests on a specified URL path and HTTP method (e.g., GET, POST). When a request is received at this endpoint, it triggers the flow and allows you to process the request and generate a response using other nodes in the flow. you can send any type of data as a response whether it is html page, JSON, string, etc.
The baseurl will be the URL of the Node-RED instance at which your flow is deployed or the URL of the Node-RED editor.
# Configuring http-in node
- Method: Specify the HTTP method (e.g., GET, POST, PUT, DELETE) that the node should listen for, for more information on Http request methods.
- URL: Define the endpoint at which it should listen. The path should look like "/test", and you can also set parameters like "/test/:id" to access them using
msg.params.id
.
# Sending response
Note: This node does not send any response to the request. The flow must include an HTTP Response node to complete the request.
# Examples
- In the example flow below, we have an HTTP In node configured with the GET method and "/test" as the URL path. This node returns an HTML page as a response when a request is received.
- In the example flow below, we have an HTTP In node configured to return the todo item as a JSON object stored in the global context, associated with the requested ID provided as a request parameter.
- In the example flow below, we have an HTTP In node configured with the POST method and "/todo" as the URL path. When a POST request containing a todo JSON object is received, it stores it in the todo list within the global context.
# Output
- payload: For a GET request, contains an object of any query string parameters. Otherwise, contains the body of the HTTP request.
- req object:
An HTTP request object. This object contains multiple properties that provide information about the request.
- body: The body of the incoming request. The format will depend on the request.
- headers: An object containing the HTTP request headers.
- query: An object containing any query string parameters.
- params: An object containing any route parameters.
- cookies: An object containing the cookies for the request.
- files: If enabled within the node, an object containing any files uploaded as part of a POST request.
- res object: An HTTP response object. This property should not be used directly;
Node Documentation
Creates an HTTP end-point for creating web services.
Outputs
Details
The node will listen on the configured path for requests of a particular type. The path can be fully specified, such as /user
, or include named parameters that accept any value, such as /user/:name
. When named parameters are used, their actual value in a request can be accessed under msg.req.params
.
For requests that include a body, such as a POST or PUT, the contents of the request is made available as msg.payload
.
If the content type of the request can be determined, the body will be parsed to any appropriate type. For example, application/json
will be parsed to its JavaScript object representation.
Note: this node does not send any response to the request. The flow must include an HTTP Response node to complete the request.