Merge pull request #620 from influxdata/flux/http-get

Flux experimental HTTP package and 'http.get()' function
pull/632/head
Scott Anderson 2019-11-20 15:16:22 -07:00 committed by GitHub
commit b3a1035ad8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,31 @@
---
title: Flux HTTP package
list_title: HTTP package
description: >
The Flux Experimental HTTP package provides functions for transferring data
using HTTP protocol.
Import the `experimental/http` package.
menu:
v2_0_ref:
name: HTTP
identifier: HTTP-exp
parent: Experimental
weight: 201
v2.0/tags: [functions, http, package]
---
The Flux Experimental HTTP package provides functions for transferring data
using HTTP protocol.
{{% warn %}}
The experimental HTTP package is subject to change at any time.
By using this package, you accept the [risks of experimental functions](/v2.0/reference/flux/stdlib/experimental/#use-experimental-functions-at-your-own-risk).
{{% /warn %}}
Import the `experimental/http` package:
```js
import "experimental/http"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,60 @@
---
title: http.get() function
description: >
The `http.get()` function submits an HTTP GET request to the specified URL and
returns the HTTP status code as an integer and the response body as a byte array.
menu:
v2_0_ref:
name: http.get
parent: HTTP-exp
weight: 301
---
The `http.get()` function submits an HTTP GET request to the specified URL and
returns the HTTP status code as an integer and the response body as a byte array.
_**Function type:** Miscellaneous_
{{% warn %}}
The `http.get()` function is currently experimental and subject to change at any time.
By using this function, you accept the [risks of experimental functions](/v2.0/reference/flux/stdlib/experimental/#use-experimental-functions-at-your-own-risk).
{{% /warn %}}
```js
import "experimental/http"
http.get(
url: "http://localhost:9999/",
headers: {x:"a", y:"b", z:"c"}
)
```
## Parameters
### url
The URL to send the GET request to.
_**Data type:** String_
### headers
Headers to include with the GET request.
_**Data type:** Object_
## Examples
##### Get the status of InfluxDB
```js
import "influxdata/influxdb/secrets"
import "experimental/http"
token = secrets.get(key: "READONLY_TOKEN")
response = http.get(
url: "http://localhost.com:9999/health",
headers: {Authorization: "Token ${token}"}
)
status = response.statusCode
body = string(v: response.body)
```