Skip to content
Not available in DartThis function is not part of the Dart package. The documentation below is for JavaScript and Python.

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 nullNone without throwing a separate exception.

However, you can receive error details via the onError event.

Parameters

NameTypeRequiredDefault
urlstringstr
httpRequestOptionsHTTPRequestOption
Request options. See the table below.
HTTPRequestOption
NameTypeRequiredDefault
authobjectdict
Authentication credentials. See the table below.
getbooleanbool
Same as method: 'get'
postbooleanbool
Same as method: 'post'
putbooleanbool
Same as method: 'put'
deletebooleanbool
Same as method: 'delete'
patchbooleanbool
Same as method: 'patch'
toStreambooleanbool
timeoutnumberint
method'get' | 'post' | 'put' | 'delete' | 'patch'
hoststringstr
If this value is not specified, the URL must be a full path.
queryParametersobjectdict
bodyobject | string | FormData | nulldict | str | FormData | None
bodyType'text' | 'json' | 'form-data' | 'x-www-form-urlencoded'
headersobject | nulldict | None
onErrorfunctionCallable
(error) => void
auth
NameTypeRequiredDefault
apiKeystringstr
'x-API-key' header
bearerstringstr
'Authorization Bearer' header

Returns

Promise<string | object | null>

str | dict | None

Examples

javascript
console.log(await fetchData('https://github.com'), { get: true });
python
print(fetchData('https://github.com'), { 'get': True })

Released under the MIT License