Home

Awesome

serialise-response

Serialise and deserialise a Fetch Response

Made with ❤ at @outlandish

<a href="http://badge.fury.io/js/serialise-response"><img alt="npm version" src="https://badge.fury.io/js/serialise-response.svg"></a> js-standard-style

Install

npm install serialise-response --save

Exported using UMD pattern, otherwise available on window as serialiseResponse and serializeResponse.

Usage

serialiseResponse(response[, toObject]) : String|Object

Serialise a Response.

Function also made available as serializeResponse.

<p>______</p>

serialiseResponse.deserialise(response) : Promise<Response>

Deserialise a Response serialised using serialise-response.

Function also made available as serializeResponse.deserialize.

Example

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 }
})

What about serialising a Request?

Check out the serialise-request sibling module.

Contributing

All pull requests and issues welcome!

If you're not sure how, check out Kent C. Dodds' great video tutorials on egghead.io!