A CLI program that fetches NASA API's and outputs them in prettified JSON format.
Written in C++ using the libcurl API and nlohmann json parser. My library TermStylist was also used for terminal colours.
References:
Clone the repository.
git clone <SSH/HTTPS URL>
Change directory.
cd NASA-libcurl-CLI
Install cURL.
# homebrew
brew install curl
# apt
sudo apt install curl
# you will probably need to add cURL to your path to override system cURL.
# this should be specified by your package manager after installation.
Change CPPFLAGS
value to your cURL include directory if necessary.
# check library include directory
curl-config --cflags
# makefile
CPPFLAGS = -std=c++17 -Wall -Wextra -g <include directory>
Change LDFLAGS
value to your cURL lib directory if necessary.
# check library link directory
curl-config --libs
# makefile
LDFLAGS = <library directory from curl-config --libs>
Create a text file to hold the NASA API key. Get your key here.
# this directory (src/key.txt) is gitignored
touch src/key.txt
Add key to the text file.
<your NASA API key>
Build program.
make build
Run a command line argument.
./src/a.o --<command line arg>
Command line arguments:
--apod
will call the function to fetch the Astronomy Picture of the day (APOD) API.
--neo-feed
will call the function to fetch the Asteroids - NeoW Feed (Neo Feed) API.
donki-sep
will call the function to fetch the DONKI Solar Energetic Particle (SEP) API.
--insight
will call the function to fetch the InSight: Mars Weather Service API.
--options
will call the function to take you to the options menu (selection prompt).
Options menu (selection prompt):
Typing apod
will call the function to fetch the Astronomy Picture of the day (APOD) API.
Typing neo-feed
will call the function to fetch the Asteroids - NeoW Feed (Neo Feed) API.
Typing donki-sep
will call the function to fetch the DONKI Solar Energetic Particle (SEP) API.
Typing insight
will call the function to fetch the InSight: Mars Weather Service API.
When you enter an option from either the menu or command line arguments, you might be asked to enter required fields to specify the API query before it fetches the JSON data string so that nlohmann json can parse it. For the ones that don't, it will go straight to fetching the JSON data string.
Here are the steps that will be executed in order:
-
Choose an option (apod, neo-feed, donki-sep, insight, etc).
-
Enter the required fields to specifiy the API query if applicable.
-
The JSON data string will be fetched by libcurl, then nlohmann json will parse that string and prettify the formatting for viewing pleasure.
-
The output of the prettified JSON will be present in the
json-out
directory, with file containing the naming scheme of<api name>.json
. The prettified JSON is also outputted to the terminal.
DONKI Solar Energetic Particle (SEP) API may have problems fetching data.