@@ -59,7 +59,60 @@ def get_request(cls):
5959 "the localhost server is active or not" )
6060 except Exception as e :
6161 print (e )
62+ @classmethod
63+ def delete_endpoint_request (cls ):
64+ request_url = cls .default_url
65+ request_headers = cls .default_headers
66+ input_url = input ('Enter URL: ' )
67+ input_headers = input ('Enter Headers: ' )
68+ if input_url != '' :
69+ request_url = input_url
70+ if input_headers != '' :
71+ try :
72+ request_headers = json .loads (input_headers )
73+ except Exception :
74+ print ("Failed to parse Input Headers" )
75+ # Check whether the request_url has an endpoint or not
76+ has_endpoint = cls .__check_endpoint (request_url )
77+
78+ # Check if http:// or https:// is present in request_url
79+ has_protocol = cls .__check_protocol (request_url )
80+
81+ if not (has_protocol ):
82+ request_url = "https://" + request_url
6283
84+ # Ask the user for endpoint if not present in request_url
85+ if not (has_endpoint ):
86+ if (request_url [- 1 ] == '/' ):
87+ endpoint = input ("Input endpoint " +
88+ "(Without the starting slash): " )
89+ else :
90+ endpoint = input ("Input endpoint (With the starting slash): " )
91+ request_url += endpoint
92+
93+ print ("Trying ...\u26A1 " )
94+ try :
95+ response = requests .delete (request_url , headers = request_headers )
96+ print (f"Reponse Status Code: { response .status_code } " )
97+ response_data = json .loads (response .content )
98+ parsed_json = json .dumps (response_data , indent = 4 )
99+ output_json = highlight (parsed_json , lexers .JsonLexer (),
100+ formatters .TerminalFormatter ())
101+ print (output_json )
102+
103+ store_data = input ('Store response data? (Y/N): ' )
104+ if (store_data == 'Y' or store_data == 'y' ):
105+ with open ('response_data.json' , 'w' ) as jsonFile :
106+ json .dump (response_data , jsonFile , indent = 4 )
107+ print ("Response data stored in response_data.json" )
108+
109+ except requests .exceptions .InvalidSchema :
110+ print ("Check whether the URL is valid or check if " +
111+ "the localhost server is active or not" )
112+ except Exception as e :
113+ print (e )
114+
115+ # Make GET request and store the response in response_data.json
63116 @classmethod
64117 def delete_endpoint_request (cls ):
65118 request_url = cls .default_url
@@ -92,6 +145,7 @@ def delete_endpoint_request(cls):
92145 request_url += endpoint
93146
94147 print ("Trying ...\u26A1 " )
148+ # Makes a DELETE request to the given endpoint
95149 try :
96150 response = requests .delete (request_url , headers = request_headers )
97151 print (f"Reponse Status Code: { response .status_code } " )
0 commit comments