Skip to content

Commit 6fda612

Browse files
docs for httpx v0.1.0 (#1120)
* docs for httpx v0.1.0 --------- Co-authored-by: Matt Dodson <[email protected]>
1 parent 25c04fb commit 6fda612

19 files changed

+174
-119
lines changed

src/data/markdown/docs/20 jslib/01 jslib/02 httpx.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It's a http client with features that are not yet available in the native module
1313
httpx module integrates well with the expect library.
1414

1515

16-
The source code is [on GitHub](https://github.com/k6io/k6-jslib-httpx). .
16+
The source code is [on GitHub](https://github.com/k6io/k6-jslib-httpx).
1717
Please request features and report bugs through [GitHub issues](https://github.com/k6io/k6-jslib-httpx/issues).
1818

1919
<Blockquote mod='attention'>
@@ -29,22 +29,23 @@ This documentation is for the only last version only. If you discover that some
2929

3030
### Methods
3131

32-
| Function | Description |
33-
| -------- | ----------- |
34-
| [request(method, url, [body], [params])](/javascript-api/jslib/httpx/request) | Generic method for making arbitrary HTTP requests. |
35-
| [get(url, [body], [params])](/javascript-api/jslib/httpx/get) | Makes GET request |
36-
| [post(url, [body], [params])](/javascript-api/jslib/httpx/post) | Makes POST request |
37-
| [put(url, [body], [params])](/javascript-api/jslib/httpx/put) | Makes PUT request |
38-
| [patch(url, [body], [params])](/javascript-api/jslib/httpx/patch) | Makes PATCH request |
39-
| [delete(url, [body], [params])](/javascript-api/jslib/httpx/delete) | Makes DELETE request |
40-
| [batch(requests)](/javascript-api/jslib/httpx/batch) | Batch multiple HTTP requests together, to issue them in parallel. |
41-
| [setBaseUrl(url)](/javascript-api/jslib/httpx/setbaseurl) | Sets the base URL for the session |
42-
| [addHeader(key, value)](/javascript-api/jslib/httpx/addheader) | Adds a header to the session |
43-
| [addHeaders(object)](/javascript-api/jslib/httpx/addheaders) | Adds multiple headers to the session |
44-
| [clearHeader(name)](/javascript-api/jslib/httpx/clearheader) | Removes header from the session |
45-
| [addTag(key, value)](/javascript-api/jslib/httpx/addtag) | Adds a tag to the session |
46-
| [addTags(object)](/javascript-api/jslib/httpx/addtags) | Adds multiple tags to the session |
47-
| [clearTag(name)](/javascript-api/jslib/httpx/cleartag) | Removes tag from the session |
32+
| Function | Description |
33+
|-----------------------------------------------------------------------------------------|-------------------------------------------------------------------|
34+
| [asyncRequest(method, url, [body], [params])](/javascript-api/jslib/httpx/asyncrequest) | Generic method for making arbitrary, asynchronous HTTP requests. |
35+
| [request(method, url, [body], [params])](/javascript-api/jslib/httpx/request) | Generic method for making arbitrary HTTP requests. |
36+
| [get(url, [body], [params])](/javascript-api/jslib/httpx/get) | Makes GET request |
37+
| [post(url, [body], [params])](/javascript-api/jslib/httpx/post) | Makes POST request |
38+
| [put(url, [body], [params])](/javascript-api/jslib/httpx/put) | Makes PUT request |
39+
| [patch(url, [body], [params])](/javascript-api/jslib/httpx/patch) | Makes PATCH request |
40+
| [delete(url, [body], [params])](/javascript-api/jslib/httpx/delete) | Makes DELETE request |
41+
| [batch(requests)](/javascript-api/jslib/httpx/batch) | Batches multiple HTTP requests together to issue them in parallel. |
42+
| [setBaseUrl(url)](/javascript-api/jslib/httpx/setbaseurl) | Sets the base URL for the session |
43+
| [addHeader(key, value)](/javascript-api/jslib/httpx/addheader) | Adds a header to the session |
44+
| [addHeaders(object)](/javascript-api/jslib/httpx/addheaders) | Adds multiple headers to the session |
45+
| [clearHeader(name)](/javascript-api/jslib/httpx/clearheader) | Removes header from the session |
46+
| [addTag(key, value)](/javascript-api/jslib/httpx/addtag) | Adds a tag to the session |
47+
| [addTags(object)](/javascript-api/jslib/httpx/addtags) | Adds multiple tags to the session |
48+
| [clearTag(name)](/javascript-api/jslib/httpx/cleartag) | Removes tag from the session |
4849

4950

5051

@@ -55,7 +56,7 @@ This documentation is for the only last version only. If you discover that some
5556

5657
```javascript
5758
import { fail } from 'k6';
58-
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.3/index.js';
59+
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
5960
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
6061

6162
const USERNAME = `user${randomIntBetween(1, 100000)}@example.com`; // random email address
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: 'asyncRequest(method, url, [body], [params])'
3+
head_title: 'httpx.asyncRequest()'
4+
description: 'Generic method for making asynchronous HTTP requests'
5+
excerpt: 'Generic method for making asynchronous HTTP requests'
6+
---
7+
8+
Generic method for making arbitrary asynchronous HTTP requests.
9+
Note, this method returns a Promise. You must use the `await` keyword to resolve it.
10+
11+
| Parameter | Type | Description |
12+
|-------------------|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
13+
| method | string | HTTP method. Must be uppercase (GET, POST, PUT, PATCH, OPTIONS, HEAD, etc) |
14+
| url | string | HTTP URL. If baseURL is set, provide only path. |
15+
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Request body; objects will be `x-www-form-urlencoded`. Set to `null` to omit the body. |
16+
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
17+
18+
19+
### Returns
20+
21+
| Type | Description |
22+
|-----------------------|------------------------------------------------------------|
23+
| Promise with Response | HTTP [Response](/javascript-api/k6-http/response) object. |
24+
25+
26+
### Example
27+
28+
<CodeGroup labels={[]}>
29+
30+
```javascript
31+
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
32+
33+
const session = new Httpx({
34+
baseURL: 'https://httpbin.test.k6.io',
35+
timeout: 20000, // 20s timeout.
36+
});
37+
38+
export default async function testSuite() {
39+
const resp_get = await session.asyncRequest('GET', `/status/200`);
40+
const resp_post = await session.asyncRequest('POST', `/status/200`, { key: 'value' });
41+
const resp_put = await session.asyncRequest('PUT', `/status/200`, { key: 'value' });
42+
const resp_patch = await session.asyncRequest('PATCH', `/status/200`, { key: 'value' });
43+
const resp_delete = await session.asyncRequest('DELETE', `/status/200`);
44+
45+
// specific methods are also available.
46+
const respGet = await session.asyncGet(`/status/200`);
47+
const respPost = await session.asyncPost(`/status/200`, { key: 'value' });
48+
const respPut = await session.asyncPut(`/status/200`, { key: 'value' });
49+
const respPatch = await session.asyncPatch(`/status/200`, { key: 'value' });
50+
const respDelete = await session.asyncDelete(`/status/200`);
51+
}
52+
```
53+
54+
</CodeGroup>

src/data/markdown/docs/20 jslib/01 jslib/02 httpx/09 request(method, url, [body], [params]).md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Generic method for making arbitrary HTTP requests.
1010
Consider using specific methods for making common requests ([get](/javascript-api/jslib/httpx/get), [post](/javascript-api/jslib/httpx/post), [put](/javascript-api/jslib/httpx/put), [patch](/javascript-api/jslib/httpx/patch))
1111

1212

13-
| Parameter | Type | Description |
14-
| -------------- | ------ | ------------------------------------------------------------------------------------ |
15-
| method | string | HTTP method. Note, the method must be uppercase (GET, POST, PUT, PATCH, OPTIONS, HEAD, etc) |
16-
| url | string | HTTP URL. If baseURL is set, provide only path. |
17-
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Request body; objects will be `x-www-form-urlencoded`. Set to `null` to omit the body. |
18-
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
13+
| Parameter | Type | Description |
14+
|-------------------|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
15+
| method | string | HTTP method. Must be uppercase (GET, POST, PUT, PATCH, OPTIONS, HEAD, etc) |
16+
| url | string | HTTP URL. If baseURL is set, provide only path. |
17+
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Request body; objects are `x-www-form-urlencoded`. To omit body, set to `null`. |
18+
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
1919

2020

2121
### Returns
@@ -30,7 +30,7 @@ Consider using specific methods for making common requests ([get](/javascript-ap
3030
<CodeGroup labels={[]}>
3131

3232
```javascript
33-
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.4/index.js';
33+
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
3434

3535
const session = new Httpx({
3636
baseURL: 'https://httpbin.test.k6.io',

src/data/markdown/docs/20 jslib/01 jslib/02 httpx/10 get(url, [body], [params]).md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ excerpt: 'httpx.get makes GET requests'
77
`session.get(url, body, params)` makes a GET request. Only the URL parameter is required
88

99

10-
| Parameter | Type | Description |
11-
| -------------- | ------ | ------------------------------------------------------------------------------------ |
12-
| url | string | HTTP URL. If baseURL is set, provide only path. |
13-
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Set to `null` to omit the body. |
14-
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
10+
| Parameter | Type | Description |
11+
|-------------------|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
12+
| url | string | HTTP URL. If baseURL is set, provide only path. |
13+
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Set to `null` to omit the body. |
14+
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
1515

1616
### Returns
1717

18-
| Type | Description |
19-
| -------------------------------------------- | --------------------- |
18+
| Type | Description |
19+
| -------------------------------------------- |-----------------------------------------------------------|
2020
| [Response](/javascript-api/k6-http/response) | HTTP [Response](/javascript-api/k6-http/response) object. |
2121

2222
### Example
2323

2424
<CodeGroup labels={[]}>
2525

2626
```javascript
27-
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.4/index.js';
27+
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
2828

2929
const session = new Httpx({
3030
baseURL: 'https://test-api.k6.io',

src/data/markdown/docs/20 jslib/01 jslib/02 httpx/11 post(url, [body], [params]).md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ excerpt: 'httpx.post makes POST requests'
66
---
77

88

9-
| Parameter | Type | Description |
10-
| -------------- | ------ | ------------------------------------------------------------------------------------ |
11-
| url | string | HTTP URL. If baseURL is set, provide only path. |
12-
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Request body; objects will be `x-www-form-urlencoded`. Set to `null` to omit the body. |
13-
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
9+
| Parameter | Type | Description |
10+
|-------------------|-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
11+
| url | string | HTTP URL. If baseURL is set, provide only path. |
12+
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Request body; objects are `x-www-form-urlencoded`. To omit body, set to `null` . |
13+
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
1414

1515
### Returns
1616

17-
| Type | Description |
18-
| -------------------------------------------- | --------------------- |
17+
| Type | Description |
18+
|----------------------------------------------|-----------------------------------------------------------|
1919
| [Response](/javascript-api/k6-http/response) | HTTP [Response](/javascript-api/k6-http/response) object. |
2020

2121

@@ -24,7 +24,7 @@ excerpt: 'httpx.post makes POST requests'
2424
<CodeGroup labels={[]}>
2525

2626
```javascript
27-
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.4/index.js';
27+
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
2828

2929
const session = new Httpx({
3030
baseURL: 'https://test-api.k6.io',

src/data/markdown/docs/20 jslib/01 jslib/02 httpx/12 put(url, [body], [params]).md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ excerpt: 'httpx.put makes PUT requests'
88
`session.put(url, body, params)` makes a PUT request. Only the first parameter is required
99

1010

11-
| Parameter | Type | Description |
12-
| -------------- | ------ | ------------------------------------------------------------------------------------ |
13-
| url | string | HTTP URL. If baseURL is set, provide only path. |
14-
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Request body; objects will be `x-www-form-urlencoded`. Set to `null` to omit the body. |
15-
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
11+
| Parameter | Type | Description |
12+
|-------------------|-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
13+
| url | string | HTTP URL. If baseURL is set, provide only path. |
14+
| body (optional) | null / string / object / ArrayBuffer / [SharedArray](/javascript-api/k6-data/sharedarray) | Request body; objects are `x-www-form-urlencoded`. To omit body, set to `null`. |
15+
| params (optional) | null or object {} | Additional [parameters](/javascript-api/k6-http/params) for this specific request. |
1616

1717
### Returns
1818

19-
| Type | Description |
20-
| -------------------------------------------- | --------------------- |
19+
| Type | Description |
20+
|----------------------------------------------|-----------------------------------------------------------|
2121
| [Response](/javascript-api/k6-http/response) | HTTP [Response](/javascript-api/k6-http/response) object. |
2222

2323

@@ -26,7 +26,7 @@ excerpt: 'httpx.put makes PUT requests'
2626
<CodeGroup labels={[]}>
2727

2828
```javascript
29-
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.4/index.js';
29+
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
3030

3131
const session = new Httpx({
3232
baseURL: 'https://httpbin.test.k6.io',

0 commit comments

Comments
 (0)