unsplash / unsplash-js

🤖 Official JavaScript wrapper for the Unsplash API
https://www.npmjs.com/package/unsplash-js
MIT License
2.13k stars 156 forks source link

Allow to specify a `fetch` implementation via the module API #123

Closed FezVrasta closed 3 years ago

FezVrasta commented 4 years ago

Right now, we need to pollute the global scope with a fetch polyfill in order to use this module.

It'd be great if the library provided an explicit API to provide the required fetch polyfill, so that an application doesn't need to pollute the global scope in order to make a single library happy.

A possible interface would look like this:

// ES Modules syntax
import Unsplash from 'unsplash-js';
import fetchPolyfill from 'node-fetch';

const unsplash = new Unsplash({
  fetch: fetchPolyfill,
  accessKey: "{APP_ACCESS_KEY}"
});
EdwardGoomba commented 3 years ago

This would be nice - I literally just imported node-fetch in the API module to run it on node.