The Wayback Machine - https://web.archive.org/web/20200614155921/https://github.com/unsplash/unsplash-js
Skip to content
🤖 A server-side JavaScript wrapper for the Unsplash API
JavaScript
Branch: master
Clone or download

Latest commit

lukechesser Merge pull request #125 from unsplash/maintenance/brotli-compression
Add note about node-fetch version to enable brotli compression
Latest commit 3b42053 Apr 17, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add default Unsplash contributing guidelines Dec 12, 2016
examples Update examples Oct 25, 2019
src Encode search keywords (Closes #99) (#119) Oct 15, 2019
test Encode search keywords (Closes #99) (#119) Oct 15, 2019
.babelrc Upgrade babel & flow Jan 13, 2016
.eslintrc Add auth methods and fix a few bugs Nov 8, 2015
.flowconfig Update babel-eslint and ignore babel libraries from flow Feb 16, 2016
.gitignore Add ES6 code coverage Nov 8, 2015
.npmignore Fix react-native .babelrc errors Apr 12, 2016
.travis.yml [6.0] Remove karma and browserstack from testing suite (#113) Oct 4, 2019
CHANGELOG.md [6.0] Update search methods to support new parameters (#116) Oct 15, 2019
LICENSE Initial commit Oct 27, 2015
README.md Add note about node-fetch version to enable brotli compression Apr 16, 2020
native.js Fix react-native .babelrc errors Apr 12, 2016
package-lock.json Add note about node-fetch version to enable brotli compression Apr 16, 2020
package.json Add note about node-fetch version to enable brotli compression Apr 16, 2020
tests.webpack.js Setup local browser tests Mar 4, 2016
webpack.config.base.js Remove node-fetch dependency Apr 12, 2016
webpack.config.development.js Remove node-fetch dependency Apr 12, 2016
webpack.config.production.js Remove node-fetch dependency Apr 12, 2016
yarn.lock Update the yarn file too. Why can't JS just have one dependency manager Apr 16, 2020

README.md

Unsplash

npm Travis

A server-side Javascript wrapper for working with the Unsplash API.

Before using the Unsplash API, you need to register as a developer and read the API Guidelines.

Quick start

Quick links to methods you're likely to care about:

Note: Every application must abide by the API Guidelines. Specifically, remember to hotlink images, attribute photographers, and trigger a download when appropriate.

Documentation

Installation

$ npm i --save unsplash-js

Dependencies

This library depends on fetch to make requests to the Unsplash API. For environments that don't support fetch, you'll need to provide a polyfill.

// ES Modules syntax
import fetch from 'node-fetch';
global.fetch = fetch;

// require syntax
const fetch = require('node-fetch');
global.fetch = fetch;

Note: we recommend using a version of node-fetch higher than 2.4.0 to benefit from Brotli compression.

Usage

If you're using unsplash-js publicly in the browser, you'll need to proxy your requests through your server to sign the requests with the Access Key and/or Secret Key to abide by the API Guideline to keep keys confidential.

Creating an instance

To create an instance, simply provide an Object with your accessKey:

// ES Modules syntax
import Unsplash from 'unsplash-js';
// require syntax
const Unsplash = require('unsplash-js').default;

const unsplash = new Unsplash({ accessKey: "{APP_ACCESS_KEY}" });

const unsplash = new Unsplash({
  accessKey: "{APP_ACCESS_KEY}",
  // Optionally you can also configure a custom header to be sent with every request
  headers: {
    "X-Custom-Header": "foo"
  },
  // Optionally if using a node-fetch polyfill or a version of fetch which supports the timeout option, you can configure the request timeout for all requests
  timeout: 500 // values set in ms
});

Credentials can be obtained from Unsplash Developers.


Error handling

unsplash.users.profile("naoufal")
  .catch(err => {
    // Your flawless error handling code
  });

Instance Methods

All the instance methods below make use of the toJson helper method described below


You can’t perform that action at this time.