DEV Community

Cover image for Fun tech quiz questions directly in your terminal
Bobby Iliev
Bobby Iliev

Posted on • Originally published at devdojo.com

Fun tech quiz questions directly in your terminal

3um936quha6qp3q3o18y.png

Introduction

Quizzes are a great way to test your knowledge on a specific topic. So I decided to create a tool called the Quiz API!

Quiz API is a simple HTTP REST API for technical quizzes including a wide variety of topics like: Linux, DevOps, Programming (PHP, JS, Python and etc.), Docker,
Kubernetes and lots more!

It is free for developers and I've just released a beta version and started adding some cool questions!

As the Quiz API returns the output in a JSON format, I created a bash script that allows you to answer questions whenever you feel like directly via your terminal!

QuizAPI Demo

Prerequisites

In order to be able to use the Quiz API bash script you need to have the following:

  • An API Key for the Quiz API, you can get it totally for free here

  • Access to a bash terminal

Download the Quiz bash script

In order to download the bash script which would allow you to consume the QuizAPI and take questions directly via your terminal, you just need to run this command here:

wget https://quizapi.io/quiz.sh
Enter fullscreen mode Exit fullscreen mode

Make sure to check the script before running it! This bash script is also available on git and you can check it's contents here:

https://github.com/QuizApi/QuizAPI-BASH/blob/master/quiz.sh

Any pull requests with improvements are more than welcome!

Install jq

The jq command-line tool is is a lightweight and flexible command-line JSON processor. It is great for parsing JSON output in your terminal and it is required by the Quiz API bash script.

If you try to run the script without having jq installed you will get the following message:

The jq command is required! Please install it and then try again
Enter fullscreen mode Exit fullscreen mode

If you don't have jq already installed, you can do that by running one of the following commands depending on your OS:

Linux

  • Ubuntu/Debian:
sudo apt-get install jq
Enter fullscreen mode Exit fullscreen mode

Or if you are running the latest Ubuntu version you might have to install it with snap:

sudo snap install jq
Enter fullscreen mode Exit fullscreen mode
  • Fedora:
sudo dnf install jq
Enter fullscreen mode Exit fullscreen mode
  • openSUSE:
sudo zypper install jq
Enter fullscreen mode Exit fullscreen mode
  • Arch:
sudo pacman -S jq
Enter fullscreen mode Exit fullscreen mode

Mac:

  • Homebrew:
brew install jq
Enter fullscreen mode Exit fullscreen mode
  • MacPort
port install jq
Enter fullscreen mode Exit fullscreen mode

If you are on a different system, follow the steps from the official documentation here:

https://stedolan.github.io/jq/download/

Usage

Once you have your API Key and jq installed you can execute the script by running the following commands:

  • Make the script executable:
chmod +x quiz.sh
Enter fullscreen mode Exit fullscreen mode
  • Execute the script:
./quiz.sh
Enter fullscreen mode Exit fullscreen mode

As we did not specify the API key, you will get the following output

Usage: quiz.sh -a API_KEY [-c Category] [-d Difficulty] [-t Tags]
Enter fullscreen mode Exit fullscreen mode

In order for the script to work, we need to pass our API key as an argument. One of the ways to do that is to define our API key as an environment variable:

export API_KEY=your_api_key_here
Enter fullscreen mode Exit fullscreen mode

Note: change the your_api_key_here with your actual Quiz API key!

Then run the following:

./quiz.sh -a ${API_KEY}
Enter fullscreen mode Exit fullscreen mode

The script will make a curl request to the Quiz API and it would pars the output for you in a nice interactive cli multiple choice quiz like this:

 "How to dump pod logs (stdout) in Kubernetes?"
  1 ) "kubectl log my-pod"
  2 ) "kubectl pod logs my-pod"
  3 ) "kubectl logs my-pod"
  4 ) "kubectl pods logs my-pod"
Check an option (again to uncheck, ENTER when done):
Enter fullscreen mode Exit fullscreen mode

You will be able to select 1 or multiple answers and then press enter:

"How to dump pod logs (stdout) in Kubernetes?"
  1 ) "kubectl log my-pod"
  2 ) "kubectl pod logs my-pod"
  3+) "kubectl logs my-pod"
  4 ) "kubectl pods logs my-pod"
"kubectl logs my-pod" was checked
Check an option (again to uncheck, ENTER when done):

Selected was:  "kubectl logs my-pod"
Correct: is:  "kubectl logs my-pod"
Correct Answer!
Enter fullscreen mode Exit fullscreen mode

Available arguments

The script allows you to specify different parameters so that you could get the questions that you want.

The available arguments are:

  • -c - get questions only for a specific category
  • -d - get questions only for a specific difficulty (Easy, Medium and Hard)
  • -t - get questions for a specific topic/tag, this lets you combine multiple topics

For example, if you wanted to get easy Docker questions only, you could run:

./quiz.sh -a ${API_KEY} -d hard -t docker
Enter fullscreen mode Exit fullscreen mode

Contributions

We have added about 1000 questions for the beta version! But we are planning to add a lot more than that in the future.

As the Quiz API is free for developers, any contributions would be greatly appreciated. If you are feeling adventurous, you could do so via this link here:

https://quizapi.io/contribute

If you notice a wrong question feel free to report it as well:

https://quizapi.io/contact

Conclusion

Quizzes can be a fun way to test and improve your knowledge, with the Quiz API you are going to be able to do so via your terminal at any time!

For more information make sure to check out the official documentation here:

https://quizapi.io/docs/1.0/overview

Also, feel free to reach out and say hi on twitter:

https://twitter.com/bobbyiliev_

Top comments (1)

Collapse
 
horomancer profile image
horomancer

I love CLI stuff. This is cool, thank you for your work on it.