Skip to content

feat: fetch-Compatible API #1939

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

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

feat: fetch-Compatible API #1939

wants to merge 10 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:

Copy link
Contributor

@sofisl sofisl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exciting! Just so we don't confuse people, can we keep the request documentation in the README as well (you can use fetch, or request)? Also, can we create a sample for request as well?

@d-goog
Copy link
Collaborator Author

d-goog commented Jun 4, 2025

Exciting! Just so we don't confuse people, can we keep the request documentation in the README as well (you can use fetch, or request)? Also, can we create a sample for request as well?

I'll update the README to mention both are available and will be supported long-term - I think we'll want to encourage folks use the fetch method going forward rather than request given flexibility of the API

@sofisl
Copy link
Contributor

sofisl commented Jun 4, 2025

Gotcha! Maybe we can keep a request sample though and mark it as not recommended? This will also help ensure we don't break the functionality since we run sample tests.

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.

2 participants