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

response.body.getReader(), as ReadableStream #95

Open
pkieltyka opened this issue Mar 21, 2020 · 2 comments
Open

response.body.getReader(), as ReadableStream #95

pkieltyka opened this issue Mar 21, 2020 · 2 comments

Comments

@pkieltyka
Copy link

pkieltyka commented Mar 21, 2020

Hi there, first I want to thank you for making this! finally a quality fetch implementation for nodejs :) Please let me know if you are accepting sponsorship, I'm happy to support!

secondly, what's your opinion on getting to api parity with the fetch spec? my personal use case is to having javascript clients that can be used in both nodejs and in browsers, I've achieved this in github.com/webrpc/webrpc example: https://github.com/webrpc/webrpc/blob/master/_examples/hello-webrpc-ts/webapp/src/client.gen.ts .. but now I am adding http streaming support to webrpc and I'd like the JS client to use identical code for node and browsers for simplicity.

Sadly, every fetch implementation for node fails to implement the readable streams with a consistent api as browsers.

example:

const consume = responseReader => {
    return responseReader.read().then(result => {
        if (result.done) { return; }

        // do something with the current chunk
        const chunk = result.value;

        return consume(responseReader);
    });
}

// Perform the request and consume response stream
fetch(url).then(response => {
    return consume(response.body.getReader());
})
.catch(console.log.bind(console));
@pkieltyka
Copy link
Author

I spent some more time reading the README and source, and seems like you made a conscious decision to use the node readablestream api over whatwg. Two questions..

  1. Why use node's api for readablestreams over whatwg?
  2. Why not make fetch-h2's api and use of readablestreams consistent with whatwg, while creating an interop layer to node ecosystem?
  3. If you don't like the second idea, what about creating a "whatwg" mode in this library which when enabled will provide the compatibility?

@chris-kruining
Copy link

Hi there, first I want to thank you for making this! finally a quality fetch implementation for nodejs :) Please let me know if you are accepting sponsorship, I'm happy to support!

secondly, what's your opinion on getting to api parity with the fetch spec? my personal use case is to having javascript clients that can be used in both nodejs and in browsers, I've achieved this in github.com/webrpc/webrpc example: https://github.com/webrpc/webrpc/blob/master/_examples/hello-webrpc-ts/webapp/src/client.gen.ts .. but now I am adding http streaming support to webrpc and I'd like the JS client to use identical code for node and browsers for simplicity.

Sadly, every fetch implementation for node fails to implement the readable streams with a consistent api as browsers.

example:

const consume = responseReader => {
    return responseReader.read().then(result => {
        if (result.done) { return; }

        // do something with the current chunk
        const chunk = result.value;

        return consume(responseReader);
    });
}

// Perform the request and consume response stream
fetch(url).then(response => {
    return consume(response.body.getReader());
})
.catch(console.log.bind(console));

dit you manage to figure this out? I am working on a streaming grpc lib and I am also running into the issue of the API's not being compatible

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

No branches or pull requests

2 participants