Mule 4 Unsplash Connector

Updated: Sep 4

Github repositories with the projects can be found at the end of the post.



What is Unsplash?


Unsplash is a website dedicated to sharing stock photography under the Unsplash license. Since 2021, it has been owned by Getty Images. The website claims over 207,000 contributing photographers and generates more than 17 billion photo impressions per month on their growing library of over 2 million photos.


Basically Unsplash allows you to download images for free and use them under Unsplash license on your web pages and projects.


Personally I’m a big fan of this community. I’ve been uploading photographs for the last couple years and it’s really amazing how many of the images uploaded have been used in a number of sites like BuzzFeed, Adobe Spark and Trello. Also many people share on Twitter and email how they wanna use my images.


Unsplash has a REST API that provides a bunch of nice features like image search, photo actions, collections, topics and users. Basically you can use all these actions to create any kind of automated application.


This time I have created a new custom connector for Mule 4 to use a couple operations (Get Random Photo and Search Photos).



Creating the custom connector


Creating a custom module (connector) is easier than you think, so let me list the steps I followed.


1. Executing the maven archetype command generate in your terminal.

mvn org.mule.extensions:mule-extensions-archetype-maven-plugin:generate

2. Then a few questions need to be answered related to the project.

Enter the name of the extension:
Enter the extension's groupId:
Enter the extension's artifactId:
Enter the extension's version: 1.0.0
Enter the extension's main package: 

3. Run the mvn eclipse:eclipse command in the terminal, so this way when we can import our projects and let it be recognized by the IDE (in case you are using Eclipse IDE). I personally like IntelliJ IDEA.


4. Import the generated project into the IDE. In my case, since I’m using the IntelliJ IDEA I select the maven project (it’s easier if the IDE is in charge of pulling the maven dependencies into the project).



Finally, the connector is imported and we are able to start working on it.


5. Now for this specific connector we are going to use only two of the auto-generated java classes: UnsplashConfiguration and UnsplashOperations.

  1. UnsplashConfiguration. Allows to set up any general parameter we might use. In this case we needed to set the Unsplash Access Key required for API calls.

  2. UnsplashOperations. Here we will specify our first operations in the connector. We should be able to include more operations later. For now we will only have GetRandomPhoto and SearchPhoto.

  3. GetRandomPhoto. Will retrieve a random picture from the API.