# New example: get random image using Unsplash REST API

**URL:** https://forum.castle-engine.io/t/new-example-get-random-image-using-unsplash-rest-api/2003
**Category:** News
**Created:** [August 30, 2025, 4:10am UTC](https://forum.castle-engine.io/t/new-example-get-random-image-using-unsplash-rest-api/2003 "2025-08-30T04:10:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [August 30, 2025, 4:10am UTC](https://forum.castle-engine.io/t/new-example-get-random-image-using-unsplash-rest-api/2003/1 "2025-08-30T04:10:59Z")

</div>

| [![Get random image from Unsplash](https://forum.castle-engine.io/uploads/default/original/2X/7/7b7158f47abb8d14f9b999a5e34c7cf4c20289e4.png)](https://castle-engine.io/wp/wp-content/uploads/2025/08/screenshot_2.png "Get random image from Unsplash") |
| [![Get random image from Unsplash](https://forum.castle-engine.io/uploads/default/original/2X/9/9ae60edee0ad02a537c94d536c63bff68350a170.png)](https://castle-engine.io/wp/wp-content/uploads/2025/08/screenshot.png "Get random image from Unsplash") |

We have a new example in our repository: [examples/network/random\_image\_from\_unsplash](https://github.com/castle-engine/castle-engine/tree/master/examples/network/random_image_from_unsplash). This shows using our `TCastleDownload` to access [Unsplash](https://unsplash.com/) API and ask for a random image matching a given search term (like a _“cute fox”_).

The main part of the example is the unit [gameunsplash.pas](https://github.com/castle-engine/castle-engine/blob/master/examples/network/random_image_from_unsplash/code/gameunsplash.pas) with a reusable class to download images from Unsplash.

There are 2 ways how this can be useful:

1. You can learn how to use `TCastleDownload` with some REST API, to access the resources in an asynchronous manner (without blocking your application).

2. And/or you can just use [gameunsplash.pas](https://github.com/castle-engine/castle-engine/blob/master/examples/network/random_image_from_unsplash/code/gameunsplash.pas) unit in your own applications (feel free to just copy it, [it’s on permissive BSD license](https://castle-engine.io/license)) to get images from Unsplash.

To use this example, you need an API key (“access key”) from Unsplash. Don’t worry, it’s rather trivial (and free) to obtain it 🙂 Please follow the [instructions in the README](https://github.com/castle-engine/castle-engine/tree/master/examples/network/random_image_from_unsplash#readme) for details.

This is based on an actual fun application I (Michalis) did this week for our family! We have a monitor playing a role of a “wall clock” powered by the Raspberry Pi, showing clock with a nice background using [TablissNG](https://github.com/BookCatKid/TablissNG) extension (a fork of it, that refreshes image from custom URL every 15 mins). I wrote a simple Pascal application to randomize the image, choosing randomly from a collection of our private photos and pretty images from Unsplash matching terms like _“cute fox”_. My daughter loves this 🙂 Note that Pascal application just exposes the image on local server, I deliberately made the separation between “display of image” (using TablissNG) and “choosing the image” (using my small Pascal program) to enable more future experiments with various fun ways to use these images.

I hope you enjoy it 🙂 And if you do, we appreciate your support on [Patreon](https://www.patreon.com/c/castleengine)!

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [August 30, 2025, 4:12am UTC](https://forum.castle-engine.io/t/new-example-get-random-image-using-unsplash-rest-api/2003/2 "2025-08-30T04:12:22Z")

</div>



---

<div class="post-metadata">

### Author: ![phomm](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/phomm/32/2827_2.png) [@phomm](https://forum.castle-engine.io/u/phomm)
#### Post date: [August 30, 2025, 10:44am UTC](https://forum.castle-engine.io/t/new-example-get-random-image-using-unsplash-rest-api/2003/3 "2025-08-30T10:44:01Z")

</div>

Cool example!  
A small note to a typo in text (in paragraph under 1):  
written “with blocking”, but should be “without”, as asynchronous implies (and the code is async as well)

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [August 30, 2025, 9:19pm UTC](https://forum.castle-engine.io/t/new-example-get-random-image-using-unsplash-rest-api/2003/4 "2025-08-30T21:19:07Z")

</div>

> [@phomm](#):
>
> written “with blocking”, but should be “without”, as asynchronous implies (and the code is async as well)

Ups!! Yes of course. Thank you, updated the post.

---

<div class="post-metadata">

### Author: ![kagamma](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/kagamma/32/226_2.png) [@kagamma](https://forum.castle-engine.io/u/kagamma)
#### Post date: [August 31, 2025, 2:58am UTC](https://forum.castle-engine.io/t/new-example-get-random-image-using-unsplash-rest-api/2003/6 "2025-08-31T02:58:18Z")

</div>

Post removed. I should have read the README more carefully 🙂
