So taking a look at this https://github.com/elysiajs/eden/blob/688011d103ec14f4fdc8f85be2e716b267ab9c5e/src/treaty/index.ts#L314-L327 block of code, I'm seeing that eden treaty can return either json data, or data as text. This is great except when you want to use Eden Treaty to download binary data or something else that needs to be treated in a particular way. Take this https://elysiajs.com/plugins/stream.html#fetch-stream feature for example. Elysia lets you stream a fetch request, basically making an endpoint into a proxy. But I don't think this will work with Eden Treaty. And what if I wanted to stream the download of a file? If the response returned is application/octet-stream Eden Treaty resolves the request and converts it to text, making it so I can't get at the binary data. The request object that's returned by calling endpoints with Eden Treaty has response.body locked, making it so the stream can't be read. SO! I have a proposed solution,
that will make it so no data property is returned and instead you'll have to handle the Response object yourself to get the data.
I have created a PR which provides a solution but without proper TypeSafety (if you set getRaw: true the signature will not change to the Response type). I welcome improvements to the PR. https://github.com/elysiajs/eden/pull/34
So taking a look at this https://github.com/elysiajs/eden/blob/688011d103ec14f4fdc8f85be2e716b267ab9c5e/src/treaty/index.ts#L314-L327 block of code, I'm seeing that eden treaty can return either json data, or data as text. This is great except when you want to use Eden Treaty to download binary data or something else that needs to be treated in a particular way. Take this https://elysiajs.com/plugins/stream.html#fetch-stream feature for example. Elysia lets you stream a fetch request, basically making an endpoint into a proxy. But I don't think this will work with Eden Treaty. And what if I wanted to stream the download of a file? If the response returned is application/octet-stream Eden Treaty resolves the request and converts it to text, making it so I can't get at the binary data. The request object that's returned by calling endpoints with Eden Treaty has response.body locked, making it so the stream can't be read. SO! I have a proposed solution,
Eden Treaty can have this block https://github.com/elysiajs/eden/blob/688011d103ec14f4fdc8f85be2e716b267ab9c5e/src/treaty/index.ts#L314-L327 extended to be helpful for more usecases like mine, but there should also be an option that can be passed into the HTTP method to get around a whole class of issues like mine:
that will make it so no data property is returned and instead you'll have to handle the Response object yourself to get the data.
I have created a PR which provides a solution but without proper TypeSafety (if you set
getRaw: true
the signature will not change to theResponse
type). I welcome improvements to the PR. https://github.com/elysiajs/eden/pull/34