What is google-gax?
The google-gax (Google API Extensions) package is a set of libraries for making Google API client libraries. It provides functionality such as automatic retries, page iteration, and request bundling. It is mainly used internally by Google's auto-generated client libraries for Node.js.
What are google-gax's main functionalities?
Automatic Retries
This feature allows developers to specify retry logic for failed requests. The RetryOptions class can be used to define backoff settings for retries.
const {RetryOptions} = require('google-gax');
const retryOptions = new RetryOptions(
[100, 200, 400, 800, 1600],
RetryOptions.createRetryPolicy()
);
Page Iteration
This feature simplifies the process of iterating over multiple pages of API response data. The createApiCall function can be configured to handle pagination automatically.
const {createApiCall} = require('google-gax');
const apiCall = createApiCall(
promiseFunc,
{autoPaginate: true}
);
const resources = [];
apiCall({},
(err, response, nextPageRequest, rawResponse) => {
resources.push(...response);
if (nextPageRequest) {
// More results to fetch
}
}
);
Request Bundling
Request bundling allows developers to combine multiple API calls into a single request to reduce network overhead. The BundleDescriptor and BundleExecutor classes are used to define and execute bundled requests.
const {BundleDescriptor, BundleExecutor} = require('google-gax');
const descriptor = new BundleDescriptor(
'bundled_field',
['field1', 'field2'],
'bundled_field',
1024
);
const executor = new BundleExecutor({descriptor});
Other packages similar to google-gax
grpc
The grpc package provides a framework for implementing RPC (Remote Procedure Call) systems, which can be used to create client and server applications. It is similar to google-gax in that it is often used for communication with Google APIs, but it is a more general-purpose library that is not specific to Google.
axios
Axios is a promise-based HTTP client for the browser and Node.js. It offers features like intercepting requests and responses, automatic transforms for JSON data, and client-side support for protecting against XSRF. While it does not provide the same API-specific extensions as google-gax, it is a popular choice for making HTTP requests in general.
aws-sdk
The AWS SDK for JavaScript allows developers to interact with AWS services from Node.js. Similar to google-gax, it provides a set of tools for working with a specific cloud provider's APIs, but it is focused on Amazon Web Services rather than Google Cloud.
Google API Extensions for Node.js
Google API Extensions for Node.js (gax-nodejs) is a set of modules which aids
the development of APIs for clients and servers based on gRPC and Google API
conventions.
Application code will rarely need to use most of the classes within this library
directly, but code generated automatically from the API definition files in
Google APIs can use services such as page streaming and request bundling to
provide a more convenient and idiomatic API surface to callers.
Node.js Versions
gax-nodejs is currently tested with Node.js 4.2.3
Contributing
Contributions to this library are always welcome and highly encouraged.
See the CONTRIBUTING documentation for more information on how to get started.
Versioning
This library follows Semantic Versioning.
It is currently in major version zero (0.y.z
), which means that anything
may change at any time and the public API should not be considered
stable.
Details
For detailed documentation of the modules in gax-nodejs, please watch [DOCUMENTATION][].
License
BSD - See LICENSE for more information.