Home

Awesome

serialise-request

Serialise and deserialise a Fetch Request

Made with ❤ at @outlandish

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

Install

npm install serialise-request --save

Exported using UMD pattern, otherwise available on window as serialiseRequest and serializeRequest.

Usage

serialiseRequest(request[, toObject]) : String|Object

Serialise a Request. (The function base64 encodes the result of calling blob().)

Function also made available as serializeRequest.

<p>______</p>

serialiseRequest.deserialise(request) : Promise<Request>

Deserialise a Request serialised using serialise-request. Caveat: as there is no way to serialise a FormData object the formData() method is unsupported on the result and will throw if called.

Function also made available as serializeRequest.deserialize.

Example

import serialiseRequest from 'serialise-request'

const serialisedRequest = serialiseRequest(
  new Request('http://foo', { bar: 'baz' })
)

// ...

const request = serialiseRequest.deserialise(serialisedRequest)

request.method //=> 'GET'
request.url //=> 'http://foo'
request.json().then((data) => {
  console.log(data) //=> { bar: 'baz' }
})

What about serialising a Response?

Check out the serialise-response 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!