Javascript fully typed wrapper for the Unsplash API.
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.
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.
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
apiUrlproperty 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
});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 });
});Create an account on Unsplash, and then on your Developer dashboard, create a new application.
- More complete and updated types.
- Automatic type inference for getRandom photos depending if
countparams is provided or not. - Bring back Authentication workflow methods.