hotfix: add more examples to requests package functions
parent
094de70674
commit
2e151cf628
|
@ -66,6 +66,7 @@ Data to send with the request.
|
|||
|
||||
### config {data-type="record"}
|
||||
Set of request configuration options.
|
||||
_See [HTTP configuration option examples](/flux/v0.x/stdlib/experimental/http/requests/#examples)._
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -98,10 +99,28 @@ requests.do(
|
|||
```js
|
||||
import "experimental/http/requests"
|
||||
|
||||
resp = requests.do(
|
||||
requests.do(
|
||||
method: "GET",
|
||||
url: "http://example.com",
|
||||
params: ["start": ["100"]],
|
||||
)
|
||||
```
|
||||
|
||||
### Output HTTP response data in a table
|
||||
```js
|
||||
import "array"
|
||||
import "dict"
|
||||
import "experimental/http/requests"
|
||||
|
||||
resp = requests.do(method: "GET", url: "http://example.com")
|
||||
|
||||
array.from(
|
||||
rows: [
|
||||
{
|
||||
body: string(v: resp.body),
|
||||
statusCode: resp.statusCode,
|
||||
date: dict.get(dict: resp.headers, key: "Date", default: ""),
|
||||
},
|
||||
],
|
||||
)
|
||||
```
|
|
@ -54,6 +54,7 @@ Data to send with the request.
|
|||
|
||||
### config {data-type="record"}
|
||||
Set of request configuration options.
|
||||
_See [HTTP configuration option examples](/flux/v0.x/stdlib/experimental/http/requests/#examples)._
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -63,3 +64,32 @@ import "experimental/http/requests"
|
|||
|
||||
requests.get(url:"http://example.com")
|
||||
```
|
||||
|
||||
### Make a GET request with authorization
|
||||
```js
|
||||
import "experimental/http/requests"
|
||||
import "influxdata/influxdb/secrets"
|
||||
|
||||
token = secrets.get(key: "TOKEN")
|
||||
|
||||
requests.get(url: "http://example.com", headers: ["Authorization": "Bearer ${token}"])
|
||||
```
|
||||
|
||||
### Output HTTP response data in a table
|
||||
```js
|
||||
import "array"
|
||||
import "dict"
|
||||
import "experimental/http/requests"
|
||||
|
||||
resp = requests.get(url: "http://example.com")
|
||||
|
||||
array.from(
|
||||
rows: [
|
||||
{
|
||||
body: string(v: resp.body),
|
||||
statusCode: resp.statusCode,
|
||||
date: dict.get(dict: resp.headers, key: "Date", default: ""),
|
||||
},
|
||||
],
|
||||
)
|
||||
```
|
||||
|
|
|
@ -54,6 +54,7 @@ Data to send with the request.
|
|||
|
||||
### config {data-type="record"}
|
||||
Set of request configuration options.
|
||||
_See [HTTP configuration option examples](/flux/v0.x/stdlib/experimental/http/requests/#examples)._
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -62,5 +63,39 @@ Set of request configuration options.
|
|||
import "json"
|
||||
import "experimental/http/requests"
|
||||
|
||||
resp = requests.post(url:"http://example.com", body: json.encode(v: {data: {x:1, y: 2, z:3}))
|
||||
requests.post(url:"http://example.com", body: json.encode(v: {data: {x:1, y: 2, z:3}))
|
||||
```
|
||||
|
||||
### Make a POST request with authorization
|
||||
```js
|
||||
import "json"
|
||||
import "experimental/http/requests"
|
||||
import "influxdata/influxdb/secrets"
|
||||
|
||||
token = secrets.get(key: "TOKEN")
|
||||
|
||||
requests.post(
|
||||
url: "http://example.com",
|
||||
body: json.encode(v: {data: {x: 1, y: 2, z: 3}}),
|
||||
headers: ["Authorization": "Bearer ${token}"],
|
||||
)
|
||||
```
|
||||
|
||||
### Output HTTP response data in a table
|
||||
```js
|
||||
import "array"
|
||||
import "dict"
|
||||
import "experimental/http/requests"
|
||||
|
||||
resp = requests.post(url: "http://example.com")
|
||||
|
||||
array.from(
|
||||
rows: [
|
||||
{
|
||||
body: string(v: resp.body),
|
||||
statusCode: resp.statusCode,
|
||||
date: dict.get(dict: resp.headers, key: "Date", default: ""),
|
||||
},
|
||||
],
|
||||
)
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue