Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

feat: fetch-Compatible API#1939

Merged
sofisl merged 12 commits intomainfrom
fetch
Jun 12, 2025
Merged

feat: fetch-Compatible API#1939
sofisl merged 12 commits intomainfrom
fetch

Conversation

@d-goog
Copy link
Contributor

@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 a review from a team February 20, 2025 21:25
@d-goog d-goog requested a review from a team as a code owner 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
@generated-files-bot
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
Contributor 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.

@d-goog d-goog closed this Jun 6, 2025
@sofisl sofisl reopened this Jun 11, 2025
@sofisl
Copy link
Contributor

sofisl commented Jun 12, 2025

We are still testing request so no need to keep the other samples.

@sofisl sofisl merged commit c63f608 into main Jun 12, 2025
17 checks passed
@sofisl sofisl deleted the fetch branch June 12, 2025 06:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants