Last time we looked at the use of node-Red file classification nodes. With storage nodes, you can create files, append content to specific files, and listen for some files to be written
In this article, I will tell you about the nodes under the network classification in Node-Red. There are 12 nodes under this classification.
mqtt in
Connect to the MQTT broker and subscribe to messages from the specified topic.mqtt out
Connect to the MQTT broker and publish the message.http in
Create the HTTP endpoint used to create the Web service.http response
Sends the response back to the request received from the HTTP input node.http request
Send the HTTP request and return the response.websocket in
WebSocket input node.websocket out
WebSocket output node.tcp in
Provides TCP input options. You can connect to a remote TCP port or accept incoming connections.tcp out
Provides options for TCP output. You can connect to a remote TCP port, accept incoming connections, or reply to messages received from a TCP In node.tcp request
A simple TCP request node. Sends msg.payload to the server’s TCP port and expects a response.udp in
UDP input node. Generates a Buffer, string, or Base64 encoded string in msg.payload. Multicast is supported.upd out
This object sends msg.payload to the specified UDP host and port. Multicast is supported.
This module is the core module of Node-Red. If you want to communicate with hardware and equipment, you need to use this module to achieve. HTTP in, HTTP out, HTTP request, ‘
http in
This node can be used to create an HTTP interface to a Web service in the following ways GET
.POST
.PUT
.DELETE
PATHC
Also supports POST upload files writing an interface is very simple
- Create an Http IN node
- Use the function node to process the data to be returned
- Use the HTTP OUT node to return data to the client
This is a completed HTTP request link.
The output from this node is as follows
Payload GET Requests an object that contains any query string parameters. Or contain the HTTP request body. ReqHTTP request object. This object contains multiple attributes about the request information.
- Body – The body of the incoming request. The format will depend on the request.
- Headers – The object that contains the HTTP request header.
- Query – An object that contains any query string arguments.
- Params – An object that contains any routing parameters.
- Cookies – Contains objects that request cookies.
- Files – The object that contains the uploaded file if file upload is enabled on the node.
Res HTTP response object. This property should not be used directly; The HTTP Response node records how requests are responded to. This property must remain on the message passed to the response node.
We create such an interface
The path of the interface is/getName using the GET request
And then add one in the backfunction
node
Then you can append the payload message body to the flow
http response
This node is used to send the HTTP response back to the client with these elements in the body of the message returned
- Payload Indicates the body of the response.
- StatusCode, if set, is used as the response statusCode. Default value: 200.
- Headers, if set, provides the HTTP header to be included in the response.
- Cookies, if set, can be used to set or delete cookies.
To create ahttp response
Chase to the previous flow
After deployment, type IP :port/ getName in your browser and you’ll see a return body like this
http request
This node sends the HTTP request and returns the response. There are inputs, there are outputs and the inputs have these parameters
url
If not configured in the node, this optional property sets the REQUESTED URL.method
If not configured in the node, this optional property sets the HTTP method for the request. It must be one of GET,PUT,POST,PATCH, or DELETE.headers
Sets the HTTP header for the request.cookies
If set, it can be used to send cookies with requests.payload
Send is the body of the request.rejectUnauthorized
If set to false, HTTPS sites that use self-signed certificates are allowed to make requests.followRedirects
If set to false, follow redirects are prevented (HTTP 301). The default value is truerequestTimeout
If set to a positive number of milliseconds, the httpRequestTimeout parameter of the global setting will be overridden.
Output parameters
payload
The body of the response. You can configure the node to return the body as a string, try to parse it as a JSON string, or leave it as a binary buffer.statusCode
The status code of the response, or an error code if the request cannot be completed.headers
The object that contains the response header.responseUrl
This property is the FINAL redirected URL if any redirection occurs while the request is being processed. Otherwise, the URL of the original request.responseCookies
If the response contains cookies, this property is the object of the ‘name/value’ key-value pair for each cookie.redirectList
If the request is redirected once or more, the accumulated information is added to this property. “Location” is the next redirect target. A cookie is a cookie returned from a redirected source.
Here is an example
Request an interface, you can configure the certificate, select the request mode
Add inject node in front of the node, which is used to trigger the interface, and add debug node to print messages after the node
Trigger the flow after deployment