Skip to content

chrisyer/unsplash-js

This branch is 1 commit ahead of, 272 commits behind unsplash/unsplash-js:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

324c07d · Nov 8, 2019
Dec 12, 2016
Oct 25, 2019
Oct 15, 2019
Oct 15, 2019
Jan 13, 2016
Nov 8, 2015
Feb 16, 2016
Nov 8, 2015
Apr 12, 2016
Oct 4, 2019
Oct 15, 2019
Oct 27, 2015
Oct 16, 2019
Apr 12, 2016
Oct 4, 2019
Mar 4, 2016
Apr 12, 2016
Apr 12, 2016
Apr 12, 2016
Oct 4, 2019

Repository files navigation

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;

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


About

🤖 A Universal JavaScript wrapper for the Unsplash API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%