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

Replaced request with node-fetch #195

Closed
wants to merge 4 commits into from
Closed

Replaced request with node-fetch #195

wants to merge 4 commits into from

Conversation

dandv
Copy link
Contributor

@dandv dandv commented Sep 23, 2016

node-tech for use with isomorphic-fetch in browsers, instead of got.

@connor4312
Copy link
Member

I believe this refers to the maxRetries option in InfluxRequest

theResponse = response
return response.text()
}).then(function (body) {
body = body === '' ? {} : JSON.parse(body) // workaround for https://github.com/bitinn/node-fetch/issues/165
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps checking the statusCode for 204s would be cleaner here? I believe the issue on node-fetch would break away from the whatwg specification, which simply states that response.json() should

[r]eturn the result of invoking the initial value of the parse property of the JSON object with the result of running utf-8 decode on bytes as argument. Rethrow any exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be less resilient to imperfect implementations that return, say, 200 and an empty response, but it would help catch that error.

I've amended my PR to node-fetch to check for a status code of 204 instead.

Copy link
Member

Choose a reason for hiding this comment

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

I agree it's less resilient, but as far as adding it in node-fetch:

  • it is a breaking API change
  • empty objects are not necessarily equivalent to empty responses
  • it breaks away from the specification which node-fetch is trying to match (!)
  • it also will not be a feature in browsers; even if github/fetch also accepts such a change, it won't be present in browsers on which the polyfill is not applied (modern Chrome/FireFox)

Copy link
Contributor Author

@dandv dandv Sep 25, 2016

Choose a reason for hiding this comment

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

Shouldn't GitHub be hiding this discussion now that it refers to an outdated diff?

@connor4312
Copy link
Member

connor4312 commented Sep 24, 2016

After some review for integration with 5.x, I'm not totally sure that using fetch, particularly moving toward isomorphic fetch, is the right way to go yet. Two reasons:

  • the de-facto standard for fetch in the browser is a global polyfill; generally I do not think that it is the place of dependencies to provide such polyfills
  • node-fetch implements some useful features like timeouts, but these are not present in the browser version (or official spec) and they would have to be special-cased; personally I'd rather drop a dependency in favor of good ol' fashioned XHR if we would have to manually do detection regardless

It seems like using the http module directly is a reasonable way to go. Its API is decently friendly and there are quality compatible API implementations for browsers which will work out of the box in most loaders. (Note that Webpack currently uses an unmaintained compatibility layer which does not support timeouts, but Browserify has moved over and it looks like Webpack will soon)

@dandv
Copy link
Contributor Author

dandv commented Sep 24, 2016

Influent works in the browser by using a small HTTP module, hurl, which uses XHR.

@dandv dandv changed the title WIP for replacing request with node-fetch Replaced request with node-fetch Sep 25, 2016
@dandv
Copy link
Contributor Author

dandv commented Sep 25, 2016

FWIW, this branch works without problems in the browser, without isomorphic-fetch. I've tested with jspm 0.17, connecting over HTTPS to the InfluxDB server.

@connor4312
Copy link
Member

connor4312 commented Oct 2, 2016

Can you rebase on or back-merge in master? Happy to add this in now, though I still want to stick with with native http module, ponyfilled with stream-promise in Webpack/Browserify, in 5.0.0 :)

@dandv
Copy link
Contributor Author

dandv commented Oct 3, 2016

@connor4312: closing in favor of the #202 rebase.

@dandv dandv closed this Oct 3, 2016
@dandv dandv deleted the fetch branch October 3, 2016 00:21
@dandv dandv restored the fetch branch October 18, 2016 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants