gaxios
An HTTP request client that provides an axios
like interface over top of node-fetch
.
Install
$ npm install gaxios
Example
const {request} = require('gaxios');
const res = await request({
url: 'https://www.googleapis.com/discovery/v1/apis/',
});
Setting Defaults
Gaxios supports setting default properties both on the default instance, and on additional instances. This is often useful when making many requests to the same domain with the same base settings. For example:
const gaxios = require('gaxios');
gaxios.instance.defaults = {
baseURL: 'https://example.com'
headers: {
Authorization: 'SOME_TOKEN'
}
}
gaxios.request({url: '/data'}).then(...);
Note that setting default values will take precedence
over other authentication methods, i.e., application default credentials.
Request Options
interface GaxiosOptions = {
url: string,
method: 'GET',
baseURL: 'https://example.com';
headers: { 'some': 'header' },
data: {
some: 'data'
},
maxContentLength: 2000,
maxRedirects: 100,
params: {
querystring: 'parameters'
},
paramsSerializer: (params) => {
return qs.stringify(params);
},
timeout: 1000,
adapter?: async (options, defaultAdapter) => {
const res = await defaultAdapter(options);
res.data = {
...res.data,
extraProperty: 'your extra property',
};
return res;
};
responseType: 'unknown',
agent: someHttpsAgent,
validateStatus: (status: number) => true,
fetchImplementation?: typeof fetch;
retryConfig: {
retry?: number;
currentRetryAttempt?: number;
httpMethodsToRetry?: string[];
statusCodesToRetry?: number[][];
onRetryAttempt?: (err: GaxiosError) => Promise<void> | void;
shouldRetry?: (err: GaxiosError) => Promise<boolean> | boolean;
noResponseRetries?: number;
retryDelay?: number;
},
retry: boolean,
signal?: AbortSignal
multipart?: GaxiosMultipartOptions;
proxy?: string | URL;
noProxy?: (string | URL | RegExp)[];
errorRedactor?: typeof defaultErrorRedactor | false;
}
License
Apache-2.0