index.js
function serialiseRequest (request, toObject) {
  if (!(request instanceof Request)) {
    throw new Error('Expecting request to be instance of Request')
  }

  var headers = []
  var headerNames = request.headers.keys()
  for (var i = 0; i < headerNames.length; i++) {
    var headerName = headerNames[i]
    headers[headerName] = request.headers.get(headerName)
  }

  var serialised = {
    method: request.method,
    url: request.url,
    headers: headers,
    context: request.context,
    referrer: request.referrer,
    mode: request.mode,
    credentials: request.credentials,
    redirect: request.redirect,
    integrity: request.integrity,
    cache: request.cache,
    bodyUsed: request.bodyUsed
  }

  return request
    .blob()
    .then(blobUtil.blobToBase64String)
    .then(function (base64) {
      serialised.__body = base64
      return toObject
        ? serialised
        : JSON.stringify(serialised)
    })
}
function serialiseRequest (request, toObject) {
  if (!(request instanceof Request)) {
    throw new Error('Expecting request to be instance of Request')
  }

  var headers = []
  var headerNames = request.headers.keys()
  for (var i = 0; i < headerNames.length; i++) {
    var headerName = headerNames[i]
    headers[headerName] = request.headers.get(headerName)
  }

  var serialised = {
    method: request.method,
    url: request.url,
    headers: headers,
    context: request.context,
    referrer: request.referrer,
    mode: request.mode,
    credentials: request.credentials,
    redirect: request.redirect,
    integrity: request.integrity,
    cache: request.cache,
    bodyUsed: request.bodyUsed
  }

  return request
    .blob()
    .then(blobUtil.blobToBase64String)
    .then(function (base64) {
      serialised.__body = base64
      return toObject
        ? serialised
        : JSON.stringify(serialised)
    })
}
function serialiseRequest ( request , toObject ) { if ( ! ( request instanceof Request ) ) { throw new Error ( 'Expecting request to be instance of Request' ) } var headers = [ ] var headerNames = request . headers . keys ( ) for ( var i = 0 ; i < headerNames . length ; i ++ ) { var headerName = headerNames [ i ] headers [ headerName ] = request . headers . get ( headerName ) } var serialised = { method : request . method , url : request . url , headers : headers , context : request . context , referrer : request . referrer , mode : request . mode , credentials : request . credentials , redirect : request . redirect , integrity : request . integrity , cache : request . cache , bodyUsed : request . bodyUsed } return request . blob ( ) . then ( blobUtil . blobToBase64String ) . then ( function ( base64 ) { serialised . __body = base64 return toObject ? serialised : JSON . stringify ( serialised ) } ) }
Serialise a Request to a string or object.
@param {Request} request
@param {Boolean} [toObject] serialise to an object
@returns {Promise}
Serialise a Request to a string or object .