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

docs: expand mixins information, notate body reuse #1209

Merged
merged 5 commits into from Apr 6, 2022

Conversation

shellscape
Copy link
Contributor

This PR proposes to resolve the documentation issue outlined in #1208.

I referenced the fetch spec in some ways I felt read naturally, and attempted to structure the docs in a way that it would read/flow from most common use cases and wanted-info to most obscure or infrequently used. Added a little sugar to references that users might find useful or interesting. I'm not married to any part of it, but want to make sure that we're pointing users in the right direction for using mixins and potential pitfalls, especially those who have been using alternatives to fetch and aren't up to speed.

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2022

Codecov Report

Merging #1209 (b2adeb4) into main (4c206cb) will increase coverage by 0.76%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #1209      +/-   ##
==========================================
+ Coverage   93.50%   94.27%   +0.76%     
==========================================
  Files          43       45       +2     
  Lines        4035     4192     +157     
==========================================
+ Hits         3773     3952     +179     
+ Misses        262      240      -22     
Impacted Files Coverage Δ
lib/fetch/response.js 84.86% <0.00%> (-10.59%) ⬇️
lib/pool-base.js 96.77% <0.00%> (-0.89%) ⬇️
lib/fetch/body.js 98.33% <0.00%> (-0.84%) ⬇️
lib/agent.js 100.00% <0.00%> (ø)
lib/proxy-agent.js 100.00% <0.00%> (ø)
lib/fetch/dataURL.js 96.52% <0.00%> (ø)
lib/fetch/headers.js 100.00% <0.00%> (ø)
lib/api/api-stream.js 100.00% <0.00%> (ø)
lib/api/api-connect.js 100.00% <0.00%> (ø)
lib/api/api-request.js 100.00% <0.00%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c206cb...b2adeb4. Read the comment docs.

README.md Outdated Show resolved Hide resolved
Co-authored-by: Robert Nagy <ronagy@icloud.com>
README.md Outdated Show resolved Hide resolved
README.md Outdated

Should you need to access the `body` in plain-text after using a mixin, the best practice is to use the `.text()` mixin first, and manually parse the text to the desired format.

If the scenario arises where you absolutely must have a copy of the result stream, [`.clone`](https://fetch.spec.whatwg.org/#dom-request-clone) can be used _before_ using a `body` mixin, or [`body.pipeThrough`](https://streams.spec.whatwg.org/#readablestream-pipe-through) with a user-defined stream [§](https://web.dev/fetch-upload-streaming), such as [`TransformStream`]https://nodejs.org/api/stream.html#duplex-and-transform-streams.
Copy link
Member

Choose a reason for hiding this comment

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

cc @ronag how do you think this can be fixed?

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by fixed?

Copy link
Member

Choose a reason for hiding this comment

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

I mean that this refer to body.pipeThrough() about the http.request() while we do not have a WHATWG stream there.

Copy link
Member

Choose a reason for hiding this comment

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

Like you suggested above. Mentions to web streams should be removed IMHO.

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 really neuter the usefulness of the paragraph. I'd really like to retain something for users to point them in the right direction. Could you suggest an edit here?

Copy link
Member

Choose a reason for hiding this comment

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

ReadableStream or anything web stream related is not relevant here. I think maybe you want to put another version of this under fetch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I can remove it. I don't think it belong under fetch because users that need to copy the result stream while using undici (and that's the important part here) should have something to reference. I understand that from a maintainer's point of view it doesn't belong, but from a user's point of view, that takes away a resource of understanding.

If we can't canonize it in the docs, would it be acceptable to open a new issue as a "how to," paste the contents above in the issue, and then close it? So at the least there'd be something searchable in the repo.

Copy link
Member

@ronag ronag Apr 6, 2022

Choose a reason for hiding this comment

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

but from a user's point of view, that takes away a resource of understanding.

I'm sorry bit I'm not sure how it belongs here even from a user's point of view. I find it misleading since there is no web stream in this part of the API.

If we can't canonize it in the docs, would it be acceptable to open a new issue as a "how to," paste the contents above in the issue, and then close it? So at the least there'd be something searchable in the repo.

Sure.

@ronag
Copy link
Member

ronag commented Mar 23, 2022

Closing as stale. If you want to resolve the comments feel free to re-open.

@ronag ronag closed this Mar 23, 2022
@shellscape
Copy link
Contributor Author

Fellas, this is a poor way to go about a PR. @ronag you've got an open conversation with @mcollina still pending. If it's stale, that's because you two fine gentleman haven't wrapped up that thread. Was happy to contribute, but please don't discount contributor efforts before maintainers have wrapped up discussion.

@ronag ronag reopened this Mar 23, 2022
shellscape and others added 2 commits March 23, 2022 12:54
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
README.md Outdated Show resolved Hide resolved
@ronag ronag merged commit 89411ab into nodejs:main Apr 6, 2022
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
* docs: expand mixins information, notate body reuse

* chore: apply suggestions from code review

Co-authored-by: Robert Nagy <ronagy@icloud.com>

* docs: remove ref to web stream.

Co-authored-by: Matteo Collina <matteo.collina@gmail.com>

* docs: remove stream clone info

* Update README.md

Co-authored-by: Robert Nagy <ronagy@icloud.com>
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* docs: expand mixins information, notate body reuse

* chore: apply suggestions from code review

Co-authored-by: Robert Nagy <ronagy@icloud.com>

* docs: remove ref to web stream.

Co-authored-by: Matteo Collina <matteo.collina@gmail.com>

* docs: remove stream clone info

* Update README.md

Co-authored-by: Robert Nagy <ronagy@icloud.com>
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* docs: expand mixins information, notate body reuse

* chore: apply suggestions from code review

Co-authored-by: Robert Nagy <ronagy@icloud.com>

* docs: remove ref to web stream.

Co-authored-by: Matteo Collina <matteo.collina@gmail.com>

* docs: remove stream clone info

* Update README.md

Co-authored-by: Robert Nagy <ronagy@icloud.com>
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
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

4 participants