Skip to content

gitter-badger/digest-fetch

 
 

Repository files navigation

digest-fetch

NPM Version NPM Downloads Build Status Test Coverage

digest auth request plugin for fetch/node-fetch.

Installation

// dependencies for node
npm install crypto-js node-fetch

// dependencies for browser
<script src='path-to-crypto-js.js'></script>

npm install digest-fetch

Get Started

const DigestFetch = require('digest-fetch')
const digestOptions = {
  cnonceSize: 32,  // length of cnonce, default: 32
  logger: console, // logger for debug, default: none
  algorithm: 'MD5' // only 'MD5' is supported now
}

const client = DigestFetch('user', 'password', digestOptions) 

// do request same way as fetch or node-fetch
const url = ''
const options = {}
client.fetch(url, options)
  .then(resp=>resp.json())
  .then(data=>console.log(data))
  .catch(e=>console.error(e))

// pass in refresh request options function for conditions options needs be refreshed when trying again.
// etc: when posting with file stream
const renew = () => ({ method: 'post', body: fs.createReadStream('path-to-file') })
client.fetch(url, {renew})
  .then(resp=>resp.json())
  .then(data=>console.log(data))
  .catch(e=>console.error(e))

About

digest auth request plugin for fetch/node-fetch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%