Python requests module helps us make Http requests to specified URL. In this article we will make a json request to this url: https://icanhazdadjoke.com/ and develop a project wherein the user enters any word and the output would be a joke related to that word.
We will be using API (library request) to search jokes using a keyword entered by the user if we get multiple results on the keyword entered then one of those jokes will be displayed randomly.
- requests module allows us to sent the Https requests using python
- pyfiglet module converts the ASCII texts to ASCII art fonts
- termcolor module helps us format color in the output terminal
- random module generates random numbers numbers in Python
- Import module
- Add header, to specify in for, is data to be stored, by default it is html text(Here, we are getting data in JSON format)
- Ask user for input
- Pass input as searching element to retrieve data from URL
- Print retrieved data.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.