Skip to main content
Home
Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score70%
Publisheda year ago (0.2.0)

Unofficial Javascript fully typed wrapper for the Unsplash API.

Unofficial Unsplash SDK

Javascript fully typed wrapper for the Unsplash API.

Why this?

For some unknown reason, the official Unsplash Javascript SDK has been archived, and it is quite outdated and/or incomplete.

With this SDK, I intend to provide a more complete and up-to-date wrapper for the Unsplash API.

The library is based in the official, but with some key changes in the response handling, which always will returns an object with the properties data, error and total.

Installation

This is a Deno package, but it can be used in Node.js as well.

You can find the installation commands for every package manager in the jsr package documentation.

Usage

Declare the client

To ensure your access keys remain confidential, the API client should be configured and run on the server. Refer to Obtaining an Unsplash Access Key for details on acquiring the key.

As mention in the official documentation:

NOTE: If you're using the SDK publicly in the browser, you'll need to proxy your requests through your server to sign the requests with the Access Key to abide by the API Guideline to keep keys confidential. We provide an apiUrl property that lets you do so. You should only need to provide one of those two values in any given scenario.

import UnsplashClient from "unsplashjs";

// On the server
const unsplash = new UnsplashClient({
  accessKey: "YOUR_ACCESS_KEY",
  //...other options
});

// On the client
const unsplash = new UnsplashClient({
  apiUrl: "https://mywebsite.com/unsplash-proxy",
  //...other options
});

Making a request

import UnsplashClient from "unsplashjs";

// On the server
const unsplash = new UnsplashClient({
  accessKey: "YOUR_ACCESS_KEY",
});

unsplash.photos.get({ photo_id: "123" }).then((result) => {
  const { data, error, total } = result;

  if (error) {
    console.error(error);
    // Handle the error
    return;
  }

  // Do something with the data
  console.log({ data });
});

Obtaining an Unsplash Access Key

Create an account on Unsplash, and then on your Developer dashboard, create a new application.

What this library adds to the official Unsplash API

  • More complete and updated types.
  • Automatic type inference for getRandom photos depending if count params is provided or not.
  • Bring back Authentication workflow methods.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@anjerodev/unsplashjs

Import symbol

import * as unsplashjs from "@anjerodev/unsplashjs";
or

Import directly with a jsr specifier

import * as unsplashjs from "jsr:@anjerodev/unsplashjs";

Add Package

pnpm i jsr:@anjerodev/unsplashjs
or (using pnpm 10.8 or older)
pnpm dlx jsr add @anjerodev/unsplashjs

Import symbol

import * as unsplashjs from "@anjerodev/unsplashjs";

Add Package

yarn add jsr:@anjerodev/unsplashjs
or (using Yarn 4.8 or older)
yarn dlx jsr add @anjerodev/unsplashjs

Import symbol

import * as unsplashjs from "@anjerodev/unsplashjs";

Add Package

vlt install jsr:@anjerodev/unsplashjs

Import symbol

import * as unsplashjs from "@anjerodev/unsplashjs";

Add Package

npx jsr add @anjerodev/unsplashjs

Import symbol

import * as unsplashjs from "@anjerodev/unsplashjs";

Add Package

bunx jsr add @anjerodev/unsplashjs

Import symbol

import * as unsplashjs from "@anjerodev/unsplashjs";