From ebc0ec00e4799ba60283dd103a694eba7d2452af Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 4 Sep 2019 11:46:03 -0600 Subject: [PATCH] finished http package, resolves #389 --- .../reference/flux/functions/http/_index.md | 4 +- .../reference/flux/functions/http/endpoint.md | 58 +++++++++++++++++++ .../reference/flux/functions/http/post.md | 7 ++- 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 content/v2.0/reference/flux/functions/http/endpoint.md diff --git a/content/v2.0/reference/flux/functions/http/_index.md b/content/v2.0/reference/flux/functions/http/_index.md index d8d589f6c..575108bfb 100644 --- a/content/v2.0/reference/flux/functions/http/_index.md +++ b/content/v2.0/reference/flux/functions/http/_index.md @@ -2,7 +2,7 @@ title: Flux HTTP package list_title: HTTP package description: > - The Flux HTTP package provides functions ... + The Flux HTTP package provides functions for transferring data using the HTTP protocol. Import the `http` package. menu: v2_0_ref: @@ -12,7 +12,7 @@ weight: 202 v2.0/tags: [functions, http, package] --- -The Flux HTTP package provides functions ... +The Flux HTTP package provides functions for transferring data using the HTTP protocol. Import the `http` package: ```js diff --git a/content/v2.0/reference/flux/functions/http/endpoint.md b/content/v2.0/reference/flux/functions/http/endpoint.md new file mode 100644 index 000000000..67e117df5 --- /dev/null +++ b/content/v2.0/reference/flux/functions/http/endpoint.md @@ -0,0 +1,58 @@ +--- +title: http.endpoint() function +description: > + The `http.endpoint()` function sends output data to a an HTTP URL using the POST request method. +menu: + v2_0_ref: + name: http.endpoint + parent: HTTP +weight: 202 +--- + +The `http.endpoint()` function sends output data to a an HTTP URL using the POST request method. + +_**Function type:** Output_ + +```js +import "http" + +http.endpoint( + url: "http://localhost:1234/" +) +``` + +## Parameters + +### url +The URL to POST to. + +_**Data type:** String_ + +### mapFn +A function that builds the object used to generate the POST request. +The object must include `headers` and `data` key-value pairs. +_For more information, see [`http.post()`](/v2.0/reference/flux/functions/http/post/)_ + +{{% note %}} +_You should rarely need to override the default `mapFn` parameter. +To see the default `mapFn` value or for insight into possible overrides, view the +[`http.endpoint()` source code](https://github.com/influxdata/flux/blob/master/stdlib/http/http.flux)._ +{{% /note %}} + +_**Data type:** Function_ + +## Examples + +##### Send critical statuses to an HTTP endpoint +```js +import "monitor" +import "http" + +endpoint = http.endpoint(url: "http://myawsomeurl.com/api/notify") + +from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses" and status == "crit") + |> map(fn: (r) => { return {status: r._status} }) + |> monitor.notify(endpoint: endpoint) +``` diff --git a/content/v2.0/reference/flux/functions/http/post.md b/content/v2.0/reference/flux/functions/http/post.md index 4a143fc39..214c15833 100644 --- a/content/v2.0/reference/flux/functions/http/post.md +++ b/content/v2.0/reference/flux/functions/http/post.md @@ -1,7 +1,8 @@ --- title: http.post() function -description: The `http.post()` function submits an HTTP POST request to the specified URL with headers and data. -// The HTTP status code is returned. +description: > + The `http.post()` function submits an HTTP POST request to the specified URL with headers and data. + The HTTP status code is returned. menu: v2_0_ref: name: http.post @@ -43,7 +44,7 @@ _**Data type:** Bytes_ ## Examples -### ... +##### Send the last reported status to a URL ```js import "json" import "http"