I was an avid user of Python as a scripting language and has used it earlier(barring last 1 year) in my profession, many a times for automation related work. However this time after a long gap Python has recently helped me to give quick turnaround for testing my rest api’s, It really saved my lot of efforts and i again started admiring it’s simplicity.
I was using Java so far for my automation until I encounter with a scenario for using the rest api’s response as an input for my scripts to perform certain tasks. After a struggle of 1 week I decided to give Python a try to interact with my application Rest API’s, So started turning over the pages of Request, a Python library for making HTTP related calls.
Day 1 of using Python request:
As soon as I read the request documentation I got a feeling, Yes! this is what something I’m looking for and more I dive deeper in the documentation it gives me the comfort of using it. Sooner I was able to send request to my API’s with not much efforts and just in 2–3 lines of code I was able to get the response from the server. Now the challenge lies is to parse the JSON response and feed the specific value of the resposne JSON to the Java automation script. So Python reads the JSON as a dictionary object and it really simplifies the way JSON needs to be parsed and used.
Day 2 of using Python request:
Now the request is made to the API’s and the response is captured and parsed as well, the next challenge forward was to execute the Python script from my Java automation scripts and use the value returned by the python scripts. So Java does allow to run the python scripts from Java code using Runtime class. After the script is run then need to get the output of the script which can be further used to execute the Java script.
Using Parameters and Headers in request:
This is how Python came as a savior for me to test the Rest API’s. Python Request module provides more generic and easier way to handle any of the GET/POST/PUT/Delete methods, so for many of us the dilemma lies like how to send the request for each of these methods? How Headers needs to be send? How Parameters needs to be integrated with the request URL?
So this entire exercise compelled me to use python as one of my favourite scripting language once again, There are libraries available for other languages as well but I never moved to use them after my encounter with Python Requests.