-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
README 2.x update proposal... take 1 #448
Conversation
Great job Jared! Rewriting manual is a tiresome job but they are critical to users, thank you for taking the time to do this. Formatting and readability wise I think this is much better than the current one. @TimothyGu @jimmywarting @gr2m if you got time, give it a quick read and let us know if there are technical details you want to amend? A few suggestions:
As for my original PR #419 , I was trying to flag some issues I would like to work on (but never did).
|
Oh dear, don't I feel sheepish.. usually I'm pretty good with making sure I'm at head... I'll get that merged in properly asap o.O Good points all around, I'll dig into each when I find a few moments :) and will await input from others as well~ Thanks for the response! EDIT: okay, should be merging properly now / all update to date info is there.. will work on suggestions next |
Codecov Report
@@ Coverage Diff @@
## master #448 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 6 6
Lines 503 503
Branches 158 158
=====================================
Hits 503 503 Continue to review full report at Codecov.
|
Somewhere i think we also should mention
I feel conflicted of what is a native stream now that both node and browser has 2 different spec. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! Some comments follow.
README.md
Outdated
|
||
#### Simple Post | ||
```javascript | ||
fetch('http://httpbin.org/post', { method: 'post', body: 'a=1' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would encourage uppercasing the method names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing that bugs me is the use of http and protocol relative urls. Should use https whenever possible to stop spying mitm attacks. Saying this cuz i know that httpbin has https
README.md
Outdated
|
||
## Loading and configuring the module | ||
We suggest you load the module via `require`, pending the stabalizing of es modules in node: | ||
```javascript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be consistent about the language tag? I'd prefer just js
.
README.md
Outdated
## Features | ||
|
||
- Stay consistent with `window.fetch` API. | ||
- Make conscious trade-off when following [whatwg fetch spec][whatwg-fetch] and [stream spec](https://streams.spec.whatwg.org/) implementation details, document known difference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: WHATWG
README.md
Outdated
#### Plain text or HTML | ||
```javascript | ||
fetch('https://github.com/') | ||
.then(res => res.text()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style-wise, the code base uses tabs for indenting. I understand why you changed it to spaces, but I feel two spaces is more common in the JavaScript world anyway.
`Accept` | `*/*` | ||
`Connection` | `close` _(when no `options.agent` is present)_ | ||
`Content-Length` | _(automatically calculated, if possible)_ | ||
`User-Agent` | `node-fetch/1.0 (+https://github.com/bitinn/node-fetch)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add Transfer-Encoding: chunked
? That header is added by Node.js automatically if the input is a stream, I believe.
Because Node.js does not implement service workers (for which this class was designed), one rarely has to construct a `Response` directly. | ||
|
||
#### response.ok | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is also spec-compliant.
README.md
Outdated
========== | ||
|
||
[![npm stable version][npm-image]][npm-url] | ||
[![npm next version][npm-next-image]][npm-url] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a next
version any more, not until we prepare for v3.x.
Might be good to also mention the fact that we don't do any proxy business, à la #449. |
It might be a good idea to reformat the options section into a table layout (like the headers section), instead of current Mainly because
Using a table might give it a bit more awareness and give us more space to write (code block isn't great for line wrapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me, just a few comments :)
|
||
Instead of implementing `XMLHttpRequest` in Node.js to run browser-specific [Fetch polyfill](https://github.com/github/fetch), why not go from native `http` to `fetch` API directly? Hence `node-fetch`, minimal code for a `window.fetch` compatible API on Node.js runtime. | ||
|
||
See Matt Andrews' [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) or Leonardo Quixada's [cross-fetch](https://github.com/lquixada/cross-fetch) for isomorphic usage (exports `node-fetch` for server-side, `whatwg-fetch` for client-side). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear to what the linked projects are. At first I thought they would be similar projects to node-fetch
, but in fact they depend on node-fetch
. Also isn’t node-fetch
itself already isomorphic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of the paragraph above, say something like this:
In case you need to support older browsers without
fetch
support, you can isomorphic-fetch. cross-fetch also adds support React Native.
|
||
## Motivation | ||
|
||
Instead of implementing `XMLHttpRequest` in Node.js to run browser-specific [Fetch polyfill](https://github.com/github/fetch), why not go from native `http` to `fetch` API directly? Hence `node-fetch`, minimal code for a `window.fetch` compatible API on Node.js runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main motivation is to reduce the size of the code that is shipped to browsers as it matters much more than it does in Node. I’m not very good with English myself, but maybe something like this:
Code size matters much more in browsers than it does in Node, so instead of implementing polyfills for node APIs in the browser,
node-fetch
implements a polyfill for the browser-nativefetch
API in the browser. No additional code needs to be send to browsers when usingnode-fetch
in your code.
|
||
## Features | ||
|
||
- Stay consistent with `window.fetch` API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d maybe remove the verb, just say "consistent with window.fetch
API."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe rename "Features" to "Goals" or "Scope"?
README.md
Outdated
|
||
## Installation | ||
|
||
Current stable release (`2.x`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe remove that? The npm badge on top shows the version, we could also move it here
README.md
Outdated
|
||
[whatwg-fetch]: https://fetch.spec.whatwg.org/ | ||
[response-init]: https://fetch.spec.whatwg.org/#responseinit | ||
[node-readable]: https://nodejs.org/api/stream.html#stream_readable_streams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move License
below Acknowledgement
@jkantr I know the suggestions are a bit overwhelming, if it's too much to fix, let's work on the factual updates first, and leave other suggestion to a later PR :) |
added "comments" (TODO link references) for changes suggested but not yet implemented for future discussion/prs clarified "native stream" to be "native Node streams" adjusted all uses of http to https to encourage secure protocol usage adjusted whatwg to proper case, WHATWG made code block tags consistent as `js` instead of `javascript` uppercased all method option values (post vs POST) added spec-compliant node to the `response.ok` api section
Sorry I've been invisible for awhile, trying to surface. Unfortunately in switching between devices and making updates in a less-than-ideal environment, I think I once again have merged the changes in a very non-optimal way. At this point should I just blow away this branch and submit a new PR with just the changes in their current state? Edit: Okay wow, I don't even know how I managed that. This is some impressively broken rebasing lol. Edit2: Alright i rewrote the rebase to a merge and i think i've kept the history intact in a reasonable way... let me know Edit3: Nope, not salvageable... will open a new PR shortly |
added "comments" (TODO link references) for changes suggested but not yet implemented for future discussion/prs clarified "native stream" to be "native Node streams" adjusted all uses of http to https to encourage secure protocol usage adjusted whatwg to proper case, WHATWG made code block tags consistent as `js` instead of `javascript` uppercased all method option values (post vs POST) added spec-compliant node to the `response.ok` api section
added "comments" (TODO link references) for changes suggested but not yet implemented for future discussion/prs clarified "native stream" to be "native Node streams" adjusted all uses of http to https to encourage secure protocol usage adjusted whatwg to proper case, WHATWG made code block tags consistent as `js` instead of `javascript` uppercased all method option values (post vs POST) added spec-compliant node to the `response.ok` api section
Closed in favor of #504 |
* v2.x readme overhaul with additions discussed in #448 added "comments" (TODO link references) for changes suggested but not yet implemented for future discussion/prs clarified "native stream" to be "native Node streams" adjusted all uses of http to https to encourage secure protocol usage adjusted whatwg to proper case, WHATWG made code block tags consistent as `js` instead of `javascript` uppercased all method option values (post vs POST) added spec-compliant node to the `response.ok` api section * fix left over cruft, inconsistent hierarchy
Just getting some feelers out there to see if this sort of thing would be received favorably. I reworked some of the structure and content of the docs, tried to make them a little more beginner friendly, take a few less liberties, be a little more consistent, and urge some best practices.
Let me know if you all think it's going in the right direction...
OH, right, also I have it identical here in a gist, if this is easier than trying to see the markdown otherwise lol:
https://gist.github.com/jkantr/1b7bcc0e660548476fbc2f184467c41e
(note, this doesn't directly refer to the points in #419 as tbh i wasn't super clear what those updates were meant for... but I could work them in I'm sure)