https://github.com/sdgluck/serialise-response
:memo: Serialise and deserialise a Fetch Response
https://github.com/sdgluck/serialise-response
Last synced: 9 months ago
JSON representation
:memo: Serialise and deserialise a Fetch Response
- Host: GitHub
- URL: https://github.com/sdgluck/serialise-response
- Owner: sdgluck
- License: mit
- Created: 2016-02-28T17:33:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-28T20:27:44.000Z (almost 10 years ago)
- Last Synced: 2025-08-06T23:18:46.566Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# serialise-response
> Serialise and deserialise a Fetch Response
Made with ❤ at [@outlandish](http://www.twitter.com/outlandish)
[](http://standardjs.com/)
## 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`
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`](https://github.com/sdgluck/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](https://egghead.io/lessons/javascript-identifying-how-to-contribute-to-an-open-source-project-on-github)!