Skip to content

sdgluck/serialise-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serialise-response

Serialise and deserialise a Fetch Response

Made with ❤ at @outlandish

npm version 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.

  • response {Response} response to serialise
  • toObject {Boolean} serialise response to an object (default is string)

______

serialiseResponse.deserialise(response) : Promise<Response>

Deserialise a Response serialised using serialise-response.

Function also made available as serializeResponse.deserialize.

  • response {String|Object} response to deserialise

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!

About

📝 Serialise and deserialise a Fetch Response

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published