The file src/api.py features the API class, which in this example is a simple controller for consuming an endpoint on the NASA open API, as exposed by the method get_image_of_day(). This method begins with the base URL for the API endpoint and attaching the following query string parameters to it:

date : specifies which date to retrieve the image for (default is today)

: specifies which date to retrieve the image for (default is today) hd : whether the API should return an HD resolution image (OK to change)

: whether the API should return an HD resolution image (OK to change) api_key: the API key specified in .env (or in .env.default if not provided)

Next, the method Util.get_json(url) is called to retrieve the JSON data that will be returned by a GET request to the specified url. This get_json() method is a simple wrapper defined in Util, which we will examine in a moment.

The returned dictionary object contains a url property which is a URL to the actual image file, which is used to download and retrieve the image with another utility class method, download_file(url, path) which we will also check out momentarily. Finally, the contents of the JSON data returned by the API are also saved to a local file with the image filename plus a .json suffix.