Closed itsgoingd closed 4 years ago
Hi @itsgoingd,
It would be very helpful if wretch supported this
Indeed, thanks for the suggestion!
should be an easy change to the convertFormData method above.
Actually there are some hidden subtlties, so I took the liberty of implementing the feature (which is now done and published in v1.7.0
).
Here is the updated documentation.
I kept the current behaviour as the default because a common use of FormData
is to upload files (most likely Blob
instances in the browser, and ReadableStream
or Buffer
instances when using a node.js polyfill) which are also of type "object" and should not be treated the same way.
I hope this change will suit your needs!
Hey, thanks for including this!
Found a small issue - combination of null values and nesting, eg. formData({ foo: null}, true)
, leads to a crash where null
is passed to Object.entries()
.
Looks like this check will need special handling of nulls, since typeof null
is object
🤦♂
https://github.com/elbywan/wretch/blob/master/src/wretcher.ts#L329-L335
Woops indeed! I just published a new release with the fix (v1.7.1
).
Thanks, good catch 👍!
Works great, thanks again.
The
formData
method can already handle arrays as seen here:https://github.com/elbywan/wretch/blob/master/src/wretcher.ts#L312-L324
But many server-side languages like PHP or Rails also support objects and even nested data, eg.
{ 'foo[bar]': 123, 'foo[baz][bar]': 456 }
.It would be very helpful if wretch supported this, should be an easy change to the
convertFormData
method above.I'm down to work on a PR if you agree on this feature.