What is Unsplash?
Unsplash is a dream that has come true to me - a free platform where free really means free: the artwork available on Unsplash is free-to-use for private and commercial use, without the need to citate the author (although it is respected if you do). Func fact: I also use Unsplash for my website's titles since January 2018.
So now that you know what Unsplash is: did you know that they have an API available with libraries for the most used programming languages? In this post I am going to dive deeper into the Node.JS module and the possibilities with it.
More about the API
The API of Unsplash is pretty cool: they have two APIs available:
- Unsplash: The default API that gives you access to all functionality
- Unsplash Source: A simplified API meant only for fetching images
I am going to discuss both APIs though, so I've got you covered on all the topics.
Using the Unsplash Source API
The Unsplash Source API is very simple and limited. As said before, it is only meant for fetching images and doing some simple inline editing tasks as well. Here's a list of what we can do with the API:
- Getting random photos
- Getting photos of a specific category (trees, nature, et cetera)
- Getting photos of a specific size (1920x1080 for example)
- Getting photos which contain a specific tag
Of course there are more use cases, but these are 4 examples of what the possibilities are with this API.
So I forked to repository and implement the needed module export. My repository is available at https://github.com/bmsimons/unsplash-source-node-js.
The returned URL is where your photo is located at, in my case it redirects to a random photo by Bernard Hermant on each visit.
You can read the readme markdown file in my repository for documentation and stuff. I have also included some more use cases over there.
Is the software provided in my repo helpful for your project? Don't forget to star it on GitHub to show your support 😉