Closed kwhitley closed 2 years ago
Are you sure you can't override the content-type? I just added a test for it and passing { headers: { "Content-Type": "text/plain" } }
and it works.
@kwhitley I've fixed the body issue in #18 as well as moved us to jsdom test env. I also added a test to verify the content-type header changing does work as intended
Thanks @danawoodman! Real quick on this, what would be the proposed way to send blob content? Currently, we attempt to JSON.stringify everything but FormData.
Currently in native fetch, you can do something like
fetch('/endpoint', {
method: 'POST',
body: blob, // content-type is sent without explicitly defining
})
without having to explicitly define or override content-type... this allows you to easily pass files without extra steps. To support that in fetcher, we'd have to manually override the pre-embedded application/json
header currently.
I'm leaning towards these behaviors:
request.body
, we pass it through to body unchanged, with no explicit content-type
headerThoughts? I just don't want to be more limiting than native fetch through our assumptions, nor make folks jump through hoops to even replicate what they were able to do easily before.
Ideal interface
const body = new Blob(['something here'], { type: 'text/plain' })
fetcher().post('/endpoint', body)
// would be equivalent to
fetch('/endpoint', { method: 'POST', body })
@kwhitley you can send arbitrary body content now, see the tests here: https://github.com/kwhitley/itty-fetcher/pull/18/files#diff-2aa640fd9240ec144ac5019315d5631742a2b12d957395a0cc6ff4a0d9cf3f02R135. My change means you can manually pass in whatever body you want and we don't stringify it.
If you want to send a diff type, I don't see passing a header as a big deal?
Expected Behavior
Actual Behavior
application/json
will be sent anywayUse Case
I am attempting to send blob data through a
fetcher
instance. I can do this with native fetch, but not itty-fetcher: