1.0.3 • Published 7 years ago
fetchware-console v1.0.3
fetchware-console
Log all fetch api calls to console without changes to api
Installation
npm install --save fetchware-console
Usage
Basic usage with default formatting status method url delay(ms)
const consoleLogger = require('fetchware-console')
const isomorphicFetch = require('isomorphic-fetch') //or use your favorite fetch implementation
const fetch = consoleLogger()(isomorphicFetch)
Custom format
const options = {
format: (date, url, options, response, ms) => console.log()
}
const fetch = consoleLogger(options)(isomorphicFetch)
Custom parameters
Decorator passes all arguments to decorated function. Useful for decorator interaction.
const consoleLogger = require('fetchware-console')
const isomorphicFetch = require('isomorphic-fetch') //or use your favorite fetch implementation
const myFetchDecorator = fetch =>
(url, options, {log}) => {
if (log)
console.log(url)
return fetch(url, options)
}
let fetch = myFetchDecorator(isomorphicFetch)
fetch = consoleLogger()(fetch)
fetch('http://github.com', {method: 'POST'}, {log: true})
Licence
MIT