serialise-request
v0.0.7
Published
Serialise and de-serialise HTML5 Requests
Downloads
419
Maintainers
Readme
serialise-request
Serialise and de-serialise HTML5 Requests
Made with ❤ at @outlandish
Install
npm install serialise-request --save
Import
ES6 Import (w/ Babel)
import serialiseRequest from 'serialise-request'
CommonJS Require
var serialiseRequest = require('serialise-request')
RequireJS
define(['serialiseRequest'], ...)
Script
<script src="/node_modules/serialise-request/dist/serialise-request.min.js"></script>
typeof window.serialiseRequest === 'object'
Usage
serialiseRequest(request[, toObject]) : String|Object
- request {Request} request to serialise
- toObject {Boolean} serialise request to an object (default is string)
serialiseRequest.deserialise(request) : Promise<Request>
- request {String|Object} serialised request to deserialise
Function names are also made available in American English: serializeRequest
and serializeRequest.deserialize
Example
import serialiseRequest from 'serialise-request'
const serialisedRequest = serialiseRequest(
new Request('http://foo', { bar: 'baz' })
)
// ...
const request = serialisedRequest.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!