The http source receives inputs via an http server.
The http server can be configured to accept HTTP or HTTPS connections. When it receives a request, it converts the request into an object as describes in the Inputs section. It will convert outputs into HTTP responses.
The following table describes the keys on the configuration object for the http source.
|String||The network address for the http server to listen on|
|Boolean||Indicates whether incoming requests are base64-encoded|
|String||Path to certificate file for establishing HTTP connections. |
|String||Path to key file for establishing HTTP connections. |
|Boolean||Indicates whether an output from an fn should be set as a response body instead of interpreting the output as a response.|
|Object||Empty object||Entries are header / value pairs. Applied when fn output does not provide headers.|
|Boolean||Indicates the output from the fn should not be included in the http response.|
|Duration||The period to wait for the server to shutdown before terminating it forcefully|
Inputs generated by the http source are objects with the following keys.
|String||The host on which the URL is sought|
|String||The network address that sent the request|
|String||The HTTP method (GET, POST, etc.)|
|String||The protocol used to make the request|
|Integer||The length of the associated content|
|String||The URI being requested|
|String||The body of the request|
|Object||Cookie name/value pairs associated with the request|
|Object||Collections of string values associated with each header key|
|Object||Collections of string values associated with each query string parameter|
If the http source is not configured with
treatOutputAsBody: true, the source
expects the output be an object with the following keys. The source will convert
the output into an http response and return it.
|Object||Header/Value pairs. If none are provided, defaults to configured |
|Object||An object to print to string and return as response body. Ignored if |
|Integer||The response status code. Defaults to |
The following example demonstrates setting up an HTTP server that accepts
:8080. It copies the output of the
fn.js into the body of the
response and sets its
Content-Type to have value
source: fnrun.source/http: treatOutputAsBody: true outputHeaders: content-type: application/json middleware: - fnrun.middleware/key: body fn: fnrun.fn/cli: node ./fn.js