Drupal-Powered Stargazing: A Module for NASA's Astronomy Picture of the Day

September 15, 2023
Effective Sept. 18, 2023, my Github repository will no longer be updated for this module. All functionality has been incorporated into the NASA Astronomy Picture of the Day module on Drupal.org.

With this module, you can effortlessly enhance your Drupal website with stunning astronomical imagery and engaging content. Whether you're building a space-related blog, an educational platform, or simply want to share the wonders of the universe, the APoD module is your gateway to a vast collection of celestial visuals.

The National Aeronautics and Space Administration (NASA) maintains serveral API enpoints to make data available to developers. One of these endpoints is a spinoff of the NASA's popular website Astronomy Picture of the Day (APoD for short) which I visit regularly myself.

I first found this API several years ago when I worked for the Space Foundation and incorporated the NASA data into their website at the time using ColdFusion. As the years went by, whenever I'd start learning a new CMS or programming language, I would use the APoD API to implement the functionality to display the daily image. My first Drupal iteration was written for Drupal 5 then I rebuilt it for Drupal 7 and started updating it for Drupal 8 but never finished it. Now I'm proud to say that I've updated it again and have fully functional module for Drupal 9 and Drupal 10.

Module Features

Drupal Service Class

The core of this module revolves around a Drupal service class with one method to retrieve the images. The method allows various parameters such as specific date, date range, random image(s), and whether images are high-def or not. The service class also caches the API results in the cache system to help prevent hitting the rate limites for the API. This is especially helpful when using the demo api key.

Routes

There are two routes provided by the module; '/astronomy-picture-of-the-day' and '/astronomy-picture-of-the-day/{date}' which is responsible for displaying the image, copyright, and description of the image. The former is a simple redirect to the later for the current date. There is also previous/next functionality to allow users to bing view previous images and videos all the way back to June 16, 1995.

Block

The module provides a simple Block plugin that allows you to specify whether to display the image for a specific date, today's date, or a random image. Just place the Astronomy Picture of the Day Block on any page and you are done.

Conclusion

The NASA's Astronomy Picture of the Day Drupal module offers a remarkable opportunity to infuse your website with the wonders of the cosmos. This module empowers web developers and astronomy enthusiasts to effortlessly integrate NASA's daily astronomy images and insightful descriptions into their Drupal-powered websites. 

Author

Ron Ferguson

0 Comments

Login or Register to post comments.