File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 11import requests , json
2+ from pygments import highlight , lexers , formatters
23
34class ApiTesting ():
45 default_url = "127.0.0.1:8000"
@@ -28,10 +29,17 @@ def get_request(cls):
2829 try :
2930 response = requests .get (request_url )
3031 print (f"Reponse Status Code: { response .status_code } " )
31- print ("Response data stored in response_data.json" )
32- parsed = json .loads (response .content )
33- with open ('response_data.json' , 'w' ) as jsonFile :
34- json .dump (parsed , jsonFile , indent = 4 )
32+ response_data = json .loads (response .content )
33+ parsed_json = json .dumps (response_data , indent = 4 )
34+ output_json = highlight (parsed_json , lexers .JsonLexer (), formatters .TerminalFormatter ())
35+ print (output_json )
36+
37+ store_data = input ('Store response data? (Y/N): ' )
38+ if (store_data == 'Y' or store_data == 'y' ):
39+ with open ('response_data.json' , 'w' ) as jsonFile :
40+ json .dump (response_data , jsonFile , indent = 4 )
41+ print ("Response data stored in response_data.json" )
42+
3543 except requests .exceptions .InvalidSchema :
3644 print ("Check whether the URL is valid or check if the localhost server is active or not" )
3745 except Exception as e :
You can’t perform that action at this time.
0 commit comments