Methods
(static) file(filePath, contentType, size) → {Object}
Create a file descriptor for multipart uploads.
Replaces `restler.file()` which is no longer available.
Parameters:
| Name | Type | Description |
|---|---|---|
filePath |
String | Path to the file |
contentType |
String | MIME type (default: application/zip) |
size |
Number | File size in bytes |
- Source:
Returns:
File descriptor object for HttpUtils.upload()
- Type
- Object
(async) request(options, httpStatusAssert, jsonOutput) → {Promise}
Establish HTTP communications using REST verbs: GET/POST/PUT/PATCH/DELETE.
Drop-in replacement for the old `request`-based implementation.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
Object | [request options: method, url, headers, body, form, json, qs, encoding] |
httpStatusAssert |
Number | Array.<Number> | [expected HTTP status code(s) — single number or array] |
jsonOutput |
Boolean | [true → parse response as JSON; false → return raw text/buffer] |
- Source:
Returns:
[resolves with JSON object or string]
- Type
- Promise
Example
const options = { method: 'GET', url: 'https://api.cf.example.com/v2/info' };
httpUtils.request(options, 200, true);
requestV2(method, url, token, data, expectedStatus) → {Promise}
Make a v2 API request.
Automatically handles form-urlencoded content type and v2-specific requirements.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
method |
String | HTTP method (GET, POST, PUT, DELETE) | |
url |
String | Request URL | |
token |
String | OAuth Authorization header value | |
data |
Object | null | Request body data (form-encoded) |
expectedStatus |
Number | 200 | Expected HTTP status code |
- Source:
Returns:
Resolves with response JSON
- Type
- Promise
requestV3(method, url, token, data, expectedStatus) → {Promise}
Make a v3 API request.
Automatically handles JSON content type and v3-specific requirements.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
method |
String | HTTP method (GET, POST, PUT, PATCH, DELETE) | |
url |
String | Request URL | |
token |
String | OAuth Authorization header value | |
data |
Object | null | Request body data (auto-stringified) |
expectedStatus |
Number | 200 | Expected HTTP status code |
- Source:
Returns:
Resolves with response JSON
- Type
- Promise
(async) upload(url, options, httpStatusAssert, jsonOutput) → {Promise}
Upload a file to Cloud Controller using multipart/form-data.
Replaces the old `restler`-based upload that was broken on Node 12+.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
String | [target URL] |
options |
Object | [upload options: method, accessToken, data, query, multipart] |
httpStatusAssert |
Number | [expected HTTP status code] |
jsonOutput |
Boolean | [true → parse response as JSON] |
- Source:
Returns:
[resolves with JSON or string]
- Type
- Promise