Skip to content

from_http

Receives HTTP/1.1 requests.

from_http url:string, [server=bool, responses=record, max_request_size=int,
tls=bool, certfile=string, keyfile=string,
password=string]

The from_http operator issues HTTP requests or spins up an HTTP/1.1 server on a given address and forwards received requests as events.

URL to listen on or to connect to.

Must have the form host[:port].

Whether to spin up an HTTP server or act as an HTTP client.

Defaults to false, i.e., the HTTP client.

:::warning Currently in Development Support for HTTP clients is not yet implemented. To get data into a pipeline with an HTTP client, use the load_http operator instead. load_http will eventually be deprecated and removed in favor of from_http. :::

Specify custom responses for endpoints on the server. For example,

responses = {
"/resource/create": { code: 200, content_type: "text/html", body: "Created!" },
"/resource/delete": { code: 401, content_type: "text/html", body: "Unauthorized!" }
}

creates two special routes on the server with different responses.

Requests to an unspecified endpoint are responded with HTTP Status 200 OK.

The maximum size of an incoming request to accept.

Defaults to 10Mib.

Enables TLS.

Defaults to false.

Path to the client certificate. Required if tls is true.

Path to the key for the client certificate. Required if tls is true.

Password for keyfile.

Spin up a server with:

from_http "0.0.0.0:8080", server=true
body = body.string().parse_json()

and send a curl request at it via:

Terminal window
echo '{"key": "value"}' | gzip | curl localhost:8080 --data-binary @- -H 'Content-Encoding: gzip'

and see it on the Tenzir side, parsed and decompressed(!):

{
headers: {
"Host": "localhost:8080",
"User-Agent": "curl/8.13.0",
"Accept": "*/*",
"Content-Encoding": "gzip",
"Content-Length": "37",
"Content-Type": "application/x-www-form-urlencoded",
},
path: "/",
method: "post",
version: "HTTP/1.1",
body: {
key: "value",
},
}

and then strip out all the HTTP framing with select:

select parsed=body
{ parsed: { key: "value" } }

serve