object-to-form-data
Transform an object/collection to FormData.
Good to use with then-busboy
![Code Coverage](https://codecov.io/github/octet-stream/object-to-form-data/coverage.svg?branch=master)
API
serialize(object[, root]) -> {FormData}
- {object} object – Object to transform
- {string} root – Root key of a fieldname
Usage
import serialize from "@octetstream/object-to-form-data"
const object = {
message: {
sender: "Glim Glam",
text: "Some whatever text message.",
attachments: [
{
file: File,
description: "Here is a description of the file"
}
]
}
}
const body = serialize(object)
const options = {
method: "POST", body
}
const onResponse = res => res.json()
const onData = data => console.log(data)
const onError = err => console.error(err)
fetch("https://api.whatever.co/ping", options)
.then(onResponse).then(onData, onError)