The httpx module is an external JavaScript library that wraps around the native k6/http module. It's a http client with features that are not yet available in the native module.
- ability to set http options globally (such as timeout)
- ability to set default tags and headers that will be used for all requests
- more user-friendly arguments to request functions (get, post, put take the same arguments)
httpx module integrates well with the expect library.
The source code is on GitHub. Please request features and report bugs through GitHub issues.
attentionThis library is in active development.
This library is stable enough to be useful, but pay attention to the new versions released on jslib.k6.io.
This documentation is for the only last version only. If you discover that some of the following doesn't work, you might be using an older version.
Methods
Function | Description |
---|---|
asyncRequest(method, url, [body], [params]) | Generic method for making arbitrary, asynchronous HTTP requests. |
request(method, url, [body], [params]) | Generic method for making arbitrary HTTP requests. |
get(url, [body], [params]) | Makes GET request |
post(url, [body], [params]) | Makes POST request |
put(url, [body], [params]) | Makes PUT request |
patch(url, [body], [params]) | Makes PATCH request |
delete(url, [body], [params]) | Makes DELETE request |
batch(requests) | Batches multiple HTTP requests together to issue them in parallel. |
setBaseUrl(url) | Sets the base URL for the session |
addHeader(key, value) | Adds a header to the session |
addHeaders(object) | Adds multiple headers to the session |
clearHeader(name) | Removes header from the session |
addTag(key, value) | Adds a tag to the session |
addTags(object) | Adds multiple tags to the session |
clearTag(name) | Removes tag from the session |
Example
httpx session