Node-RED 系列(6)-- Core nodes (Http In/Http Request)

Http In

Creates an HTTP end-point for creating web services.

Outputs
\color{red}{payload}
For a GET request, contains an object of any query string parameters. Otherwise, contains the body of the HTTP request.

\color{red}{req}
An HTTP request object. This object contains multiple properties that provide information about the request.

  • \color{red}{body} - the body of the incoming request. The format will depend on the request.
  • \color{red}{headers} - an object containing the HTTP request headers.
  • \color{red}{params} - an object containing any route parameters.
  • \color{red}{cookies} - an object containing the cookies for the request.
  • \color{red}{files} - if enabled within the node, an object containing any files uploaded as part of a POST request.

\color{red}{res}
An HTTP response object. This property should not be used directly; the HTTP Response node documents how to respond to a request. This property must remain attached to the message passed to response node.

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 request 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 follow must include an HTTP Response node to complete the request.

Usage example:
Source:

Http Request

Sends HTTP requests and returns the response.

Inputs
\color{red}{url}
If not configured in the node, this optional property sets the url of the request.

\color{red}{method}
If not configured in the node, this optional property sets the HTTP method of the request. Must be one of GET, PUT, POST, PATCH or DELETE.

\color{red}{headers}
Sets the HTTP headers of the request.

\color{red}{cookies}
If set, can be used to send cookies with the request.

\color{red}{payload}
Sent as the body of the request.

\color{red}{rejectUnauthorized}
If set to false, allows requests to be made to https sites that use self signed certificates.

\color{red}{followRedirects}
If set to false prevent following Redirect(HTTP 301). true by default.

\color{red}{requestTimeout}
If set to a positive number of milliseconds, will override the globally set httpRequestTimeout parameter.

Outputs

\color{red}{payload}
The body of the response. The node can be configured to return the body as a string, attempt to parse it as a JSON string or leave it as a binary buffer.

\color{red}{statusCode}
The status code of the response, or the error code if the request could not be completed.

\color{red}{headers}
An object containing the response headers.

\color{red}{responseUrl}
In case any redirects occurred while processing the request, this property is the final redirected url. Otherwise, the url of the original request.

\color{red}{responseCookies}
If the response includes cookies, this property is an object of name/value pairs for each cookie.

\color{red}{redirectList}
If the request was redirected one or more times, the accumulated information will be added to this property. 'location' is the next destination. 'cookies' is the cookies returned from the redirect souce.

Usage example:
Source:

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容