fetchData 
Requires a Node.js runtime ('qsu/node')This function is used to make node:fetch easier to use while ensuring data is returned regardless of the response status. By default, it uses the GET method, but other methods such as POST can also be used with separate options.
Depending on the Content-Type of the request URL, the returned data can be either a string or an object.
If the request fails, returns a 204 (No Content) status code, or an error occurs, it returns null without throwing a separate exception.
However, you can receive error details via the onError event.
Parameters
| Name | Type | Required | Default |
|---|---|---|---|
url | string | ● | – |
httpRequestOptions | HTTPRequestOption | – | – |
| Request options. See the table below. | |||
HTTPRequestOption| Name | Type | Required | Default |
|---|---|---|---|
auth | object | – | – |
| Authentication credentials. See the table below. | |||
get | boolean | – | – |
Same as method: 'get' | |||
post | boolean | – | – |
Same as method: 'post' | |||
put | boolean | – | – |
Same as method: 'put' | |||
delete | boolean | – | – |
Same as method: 'delete' | |||
patch | boolean | – | – |
Same as method: 'patch' | |||
toStream | boolean | – | – |
timeout | number | – | – |
method | 'get' | 'post' | 'put' | 'delete' | 'patch' | – | – |
host | string | – | – |
| If this value is not specified, the URL must be a full path. | |||
queryParameters | object | – | – |
body | object | string | FormData | null | – | – |
bodyType | 'text' | 'json' | 'form-data' | 'x-www-form-urlencoded' | – | – |
headers | object | null | – | – |
onError | function | – | – |
| (error) => void | |||
auth| Name | Type | Required | Default |
|---|---|---|---|
apiKey | string | – | – |
| 'x-API-key' header | |||
bearer | string | – | – |
| 'Authorization Bearer' header | |||
Returns
string | null | object
Examples
javascript
console.log(await fetchData('https://github.com'), { get: true });python
print(fetchData('https://github.com'), { 'get': True })