Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch-Compatible API #1939

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

feat: fetch-Compatible API #1939

wants to merge 3 commits into from

Conversation

d-goog
Copy link
Collaborator

@d-goog d-goog commented Feb 20, 2025

Description

This will greatly improve ergonomics for customers and our downstream libraries. Notably:

  • GoogleAuth/AuthClient can be a drop-in replacement for libraries requiring fetch-API compliance

Here's an example for customers wanting this functionality:

Impact

Customers can now streamline their request management to:

const auth = new GoogleAuth();
const fetchWithAuth: typeof fetch = (...args) => auth.fetch(...args);
await fetchWithAuth('https://example.com');

Testing

Added tests and updated some samples to use #fetch.

Additional Information

To avoid parsing/marshaling the returned data from GoogleAuth#fetch/AuthClient#fetch to GaxiosResponse#data, set {responseType: 'stream'} for the GaxiosOptions.
This can be useful when using this API as a drop-in replacement for fetch and the receiving API expects Response#bodyUsed to be false.
We could expose a noMarshalFetchData option here for AuthClientOptions or upstream in GaxiosOptions if this becomes a widely-desired feature.

Builds on:

🦕

@d-goog d-goog requested review from a team as code owners February 20, 2025 21:25
@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Feb 20, 2025
Copy link

Warning: This pull request is touching the following templated files:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant