You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was hoping to use fetch in Node, and to pass a Buffer as request body, but this is not currently possible.
main::EffectUnit
main = do
buffer <-Buffer.fromString "Hello, world"UTF8Aff.launchAff_ do
void (Fetch.fetchBody "http://example.com" { body: buffer })
This fails to compile because there's no ToRequestBody instance for Buffer.
I opened an issue in web-fetchpurescript-web/purescript-web-fetch#15 about adding RequestBody.fromBuffer (which would enable adding a ToRequestBody Buffer instance here) but that's not the right approach as it would incur a dependency on node-buffer and make both the "core" web-fetch and this fetch not portable between environments.
I think maybe a better solution would be to have instance ToRequestBody RequestBody in this library, and then a hypothetical node-fetch could wrap this fetch implementation and have its own RequestBody module with Node-specific conversion functions like fromBuffer :: Buffer -> RequestBody:
main::EffectUnit
main = do
buffer <-Buffer.fromString "Hello, world"UTF8Aff.launchAff_ do
void (Fetch.fetchBody "http://example.com" { body: RequestBody.fromBuffer buffer })
Let me know if that makes sense, or if there are reasons for omitting the instance ToRequestBody RequestBody that I'm over-looking. Thanks!
The text was updated successfully, but these errors were encountered:
I was hoping to use
fetch
in Node, and to pass aBuffer
as request body, but this is not currently possible.This fails to compile because there's no
ToRequestBody
instance forBuffer
.I opened an issue in
web-fetch
purescript-web/purescript-web-fetch#15 about addingRequestBody.fromBuffer
(which would enable adding aToRequestBody Buffer
instance here) but that's not the right approach as it would incur a dependency onnode-buffer
and make both the "core"web-fetch
and thisfetch
not portable between environments.I think maybe a better solution would be to have
instance ToRequestBody RequestBody
in this library, and then a hypotheticalnode-fetch
could wrap thisfetch
implementation and have its ownRequestBody
module with Node-specific conversion functions likefromBuffer :: Buffer -> RequestBody
:Let me know if that makes sense, or if there are reasons for omitting the
instance ToRequestBody RequestBody
that I'm over-looking. Thanks!The text was updated successfully, but these errors were encountered: