Using Open Data APIs to Find Local Sunset, Sunrise, and Moon Phase

Bill Doerrfeld | December 1, 2020

While on vacation last year I had a little fun writing some basic API use cases. I just wanted some simple landing pages that would show me helpful celestial data. When is sunset in my local timezone? When is the sunrise? What phase is the moon in?


You can view these three websites here: Sunset, Sunrise, Phase. Each should calculate each question correctly based on your local timezone. Below, I explain the process and link to the Github repos. 


sunset 🌇

Github

sunset is a super simple website that uses open data APIs to display the sunset time in your local timezone. Sunset demonstrates how to use HTTP GET calls to open data APIs. First, the code calls the GeoIPLookup.io API to return latitude and longitude coordinates based on the caller's IP address. Next, it passes these coordinates as parameters in a call to the Sunrise-Sunset API. The Sunrise-Sunset API returns the UTC timestamp for the sunset time. Lastly, sunset converts UTC into local time. It uses some JS functions to do that, and some janky slice methods to output what we want to see.


sunrise 🌄

Github

Sunrise is a super simple website that uses open data APIs to display the sunrise time in your local timezone. Sunrise demonstrates how to use HTTP GET calls to open data APIs. First, the code calls the GeoIPLookup.io API to return latitude and longitude coordinates based on the caller's IP address. Next, it uses passes these coordinates as parameters in a call to the Sunrise-Sunset API. The Sunrise-Sunset API returns the UTC timestamp for the sunrise time. Lastly, sunrise converts UTC into local time. It uses some JS functions to do that, and some janky slice methods to output what we want to see.


phase 🌘

Github

The moon is pretty lit. But just how lit is it? This simple one page site visually represents the current phase of the moon. I built it to demo an introductory example of practical API use cases. It's just a phase. phase calls the Farmsense API to display moon data. The Farmsense API is a free-to-use open API that returns useful moon phase and illumination data. After much research, it was the only free service I could find that returned the data I wanted. Given a unix timestamp, Farmsense returns information on the current moon phase, illumination percentage, and colloquial phase name. Depending on what the API returns, the script loads different images to reflect the current moon phase and illumination percentage. I also added a little bit of my own scientific interpretation on how lit the moon is.


🌘🌓🌔🌕🌖🌗🌒


Disclaimer

I built these projects to demo an introductory lesson on practical API use cases. As they are strictly demos they are not that great. Since Sunset and Sunrise depend on the caller's IP address, mobile use may return an incorrect time. Code is not elegant, it's just for sample purposes.


Other Blog Posts

By Bill Doerrfeld March 30, 2026
My first-ever contribution to CSO Online looks at the shifting landscape, from perimeter-based security to API security, and how CISOs are responding.
By Bill Doerrfeld March 29, 2026
My latest feature for The New Stack looks into solutions being proposed to fix open source Slopmageddon.
A digital pattern of rounded rectangular blocks in shades of blue and purple, arranged in an interlocking layout.
By Bill Doerrfeld March 27, 2026
My latest DirectorPlus looks at how agentic AI is reshaping platform engineering at Squarespace: less shared code and more developer experience focus.
By Bill Doerrfeld March 19, 2026
Usage-based pricing is reshaping the API economy. Discover 5 API monetization success stories, including OpenAI, Plaid, and AssemblyAI.
A lightbulb against a purple background, containing a human brain with an
By Bill Doerrfeld March 18, 2026
Why event-driven APIs matter for AI workflows, enabling real-time data, scalable systems, and responsive agent behavior.
By Bill Doerrfeld February 28, 2026
While hardware usually gets the spotlight in physical AI, the real differentiator won't be hardware. It'll be the models.
By Bill Doerrfeld February 27, 2026
In the latest DirectorPlus, Workato's CTO explains how MCP-enabled integration catalyzed internal AI usage and ROI.
By Bill Doerrfeld February 18, 2026
My latest on InfoWorld reviews MCP servers from 5 major cloud providers
By Bill Doerrfeld February 18, 2026
How are organizations actually using agentic knowledge bases in practice? My article for The New Stack looks at six emerging patterns.
eBPF in Production Report
By Bill Doerrfeld February 12, 2026
My report for the eBPF Foundation explores enterprise eBPF case studies, production deployments, and real business outcomes across cloud-native environments.