Skip to content

Conversation

@ryanseys
Copy link
Contributor

Adding apiResponse to the callbacks of every API.

  • BigQuery
  • Datastore
  • PubSub
  • Storage
  • Unit tests
  • Regression tests (doesn't make sense)

Fixes #434

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 17, 2015
@ryanseys ryanseys self-assigned this Mar 17, 2015
@ryanseys ryanseys added the core label Mar 17, 2015
@stephenplusplus
Copy link
Contributor

Looking clean so far 👍

@ryanseys
Copy link
Contributor Author

Thanks! Do you think this is appropriate for datastore or what approach should we take there?

@stephenplusplus
Copy link
Contributor

We do a lot of convenience wrapping of the response (all that entityTo___ stuff), so I think the decoded response will be the closest thing to a "raw" response.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@ryanseys
Copy link
Contributor Author

ryanseys commented Apr 7, 2015

TADA! 🎆 🚨

This PR should be ready for a review. This PR goes down in my books as one of the most tedious and boring PRs of all time. 😄

@ryanseys
Copy link
Contributor Author

ryanseys commented Apr 7, 2015

I plan to squash, but I figure it might be easier to review with the nice separate diffs.

@ryanseys
Copy link
Contributor Author

ryanseys commented Apr 7, 2015

I left out file#createReadStream and file#createWriteStream because there's many different types of responses or paths that can be taken where the apiResponses aren't really necessary. And we're dealing with responses that probably won't be any use to the end users. In your (@stephenplusplus) refactor of these methods, it might be nice to consider how the apiResponse objects could be returned with these methods.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

@sindresorhus We've been designing gcloud-node to give users curated, massaged responses from their API calls. The upstream API response can be quite intimidating/non-user friendly, which is why we try to clean it up. However, we've hit a couple places where we forgot to include something and/or didn't want to include it, because it doesn't fit the majority use case. To support cases like these, we want to give users the raw API response in a "it's there if you need it, ignore it if you don't care" kind of way.

This PR is our solution, which tacks on that raw response as the final argument to their callback:

// old
bucket.upload('file.jpg', function (err, file) {});
// new
bucket.upload('file.jpg', function (err, file, apiResponse) {});

Quite a bit uglier, but we have methods that return more than just two arguments to the callback:

// old
dataset.get(key, function (err, results, nextQuery) {});
// new
dataset.get(key, function (err, results, nextQuery, apiResults) {});

I'm wondering if you've come across APIs that have solved for the same problem, and if our solution seems reasonable. Thanks!

@ryanseys
Copy link
Contributor Author

Seems this has gotten out of sync with master. I'll rebase once we hear back from sindre.

@sindresorhus
Copy link

I'm wondering if you've come across APIs that have solved for the same problem, and if our solution seems reasonable. Thanks!

I guess that makes sense. I do that in my got module too, and so does request, albeit different order.

@stephenplusplus
Copy link
Contributor

Cool, thanks!

Once the out of sync-ness is resolved, I think we're merge-ready.

@ryanseys
Copy link
Contributor Author

Rebased and squashed. Merge when ready!

stephenplusplus added a commit that referenced this pull request Apr 16, 2015
@stephenplusplus stephenplusplus merged commit b191a22 into googleapis:master Apr 16, 2015
@stephenplusplus
Copy link
Contributor

Yay!

@ryanseys
Copy link
Contributor Author

Wewt!

@ryanseys ryanseys deleted the add-apiResponses branch April 16, 2015 21:49
@sunnychow
Copy link

thanks!

sofisl pushed a commit that referenced this pull request Sep 16, 2022
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [sinon](https://sinonjs.org/) ([source](https://togithub.com/sinonjs/sinon)) | [`^10.0.0` -> `^11.0.0`](https://renovatebot.com/diffs/npm/sinon/10.0.0/11.1.0) | [![age](https://badges.renovateapi.com/packages/npm/sinon/11.1.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/sinon/11.1.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/sinon/11.1.0/compatibility-slim/10.0.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/sinon/11.1.0/confidence-slim/10.0.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>sinonjs/sinon</summary>

### [`v11.1.0`](https://togithub.com/sinonjs/sinon/blob/master/CHANGELOG.md#&#8203;1110--2021-05-25)

[Compare Source](https://togithub.com/sinonjs/sinon/compare/v11.0.0...31be9a5d5a4762ef01cb195f29024616dfee9ce8)

\==================

-   Add sinon.promise() implementation ([#&#8203;2369](https://togithub.com/sinonjs/sinon/issues/2369))
-   Set wrappedMethod on getters/setters ([#&#8203;2378](https://togithub.com/sinonjs/sinon/issues/2378))
-   \[Docs] Update fake-server usage & descriptions ([#&#8203;2365](https://togithub.com/sinonjs/sinon/issues/2365))
-   Fake docs improvement ([#&#8203;2360](https://togithub.com/sinonjs/sinon/issues/2360))
-   Update nise to 5.1.0 (fixed [#&#8203;2318](https://togithub.com/sinonjs/sinon/issues/2318))

### [`v11.0.0`](https://togithub.com/sinonjs/sinon/blob/master/CHANGELOG.md#&#8203;1100--2021-05-24)

[Compare Source](https://togithub.com/sinonjs/sinon/compare/v10.0.1...v11.0.0)

\==================

-   Explicitly use samsam 6.0.2 with fix for [#&#8203;2345](https://togithub.com/sinonjs/sinon/issues/2345)
-   Update most packages ([#&#8203;2371](https://togithub.com/sinonjs/sinon/issues/2371))
-   Update compatibility docs ([#&#8203;2366](https://togithub.com/sinonjs/sinon/issues/2366))
-   Update packages (includes breaking fake-timers change, see [#&#8203;2352](https://togithub.com/sinonjs/sinon/issues/2352))
-   Warn of potential memory leaks ([#&#8203;2357](https://togithub.com/sinonjs/sinon/issues/2357))
-   Fix clock test errors

### [`v10.0.1`](https://togithub.com/sinonjs/sinon/blob/master/CHANGELOG.md#&#8203;1001--2021-04-08)

[Compare Source](https://togithub.com/sinonjs/sinon/compare/v10.0.0...v10.0.1)

\==================

-   Upgrade sinon components (bumps y18n to 4.0.1)
-   Bump y18n from 4.0.0 to 4.0.1

</details>

---

### Configuration

📅 **Schedule**: "after 9am and before 3pm" (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻️ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-os-login).
GautamSharda pushed a commit that referenced this pull request Jan 15, 2026
* Add semistandard as a devDependency

* Fix storage tests

* Fix language tests

* Update (some) dependencies

* Fix language slackbot tests
GautamSharda pushed a commit that referenced this pull request Jan 20, 2026
* Add semistandard as a devDependency

* Fix storage tests

* Fix language tests

* Update (some) dependencies

* Fix language slackbot tests
GautamSharda pushed a commit that referenced this pull request Jan 21, 2026
* Add semistandard as a devDependency

* Fix storage tests

* Fix language tests

* Update (some) dependencies

* Fix language slackbot tests
miguelvelezsa pushed a commit that referenced this pull request Jan 28, 2026
* Add semistandard as a devDependency

* Fix storage tests

* Fix language tests

* Update (some) dependencies

* Fix language slackbot tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return raw response object for all API calls

5 participants