Serialise and deserialise a Fetch Response
Made with ❤ at @outlandish
npm install serialise-response --save
Exported using UMD pattern, otherwise available on window
as serialiseResponse
and serializeResponse
.
Serialise a Response.
Function also made available as serializeResponse
.
- response {Response} response to serialise
- toObject {Boolean} serialise response to an object (default is string)
______
Deserialise a Response serialised using serialise-response
.
Function also made available as serializeResponse.deserialize
.
- response {String|Object} response to deserialise
import serialiseResponse from 'serialise-response'
const serialisedResponse = serialiseResponse(
new Response({ foo: 'bar' }))
)
// ...
const response = serialiseResponse.deserialise(serialisedResponse)
response.json().then((data) => {
console.log(data) //=> { foo: bar }
})
Check out the serialise-request
sibling module.
All pull requests and issues welcome!
If you're not sure how, check out Kent C. Dodds' great video tutorials on egghead.io!