1.0.2 • Published 7 years ago

fetchware-base-url v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

fetchware-base-url

npm version build status coverage status dependencies

Prefixes all fetched urls with specified value without changes to fetch api

Installation

npm install --save fetchware-base-url

Usage

Here is an example of usage with isomorphic-fetch.

const baseUrl = require('fetchware-base-url')
const isomorphicFetch = require('isomorphic-fetch') //or use your favorite fetch implementation

const fetch = baseUrl('http://github.com')(isomorphicFetch)

fetch('/ct0r').then(response => ...) //request to http://github.com/ct0r

Custom parameters

Decorator passes all arguments to decorated function. Useful for decorator interaction.

const baseUrl = require('fetchware-base-url')
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 = baseUrl('http://github.com')(fetch)

fetch('/ct0r', {method: 'POST'}, {log: true})

Licence

MIT