File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ Options: <br>
4646` -d, --debug -> Turn on Debugging mode ` <br >
4747` -c, --custom -> Setup a custom API key ` <br >
4848` -h, --help -> Shows this message and exit ` <br >
49+ ` -GET -> Make a GET request to an API ` <br >
4950
5051## License🗄
5152
Original file line number Diff line number Diff line change 44class Api_Testing ():
55 default_url = "127.0.0.1:8000"
66
7+ # Make GET request
78 @classmethod
89 def get_request (self ):
910 request_url = Api_Testing .default_url
1011 input_url = input ('Enter URL: ' )
1112 if input_url != '' :
1213 request_url = input_url
1314
15+ # Check whether the request_url has an endpoint or not
1416 has_endpoint = self .check_endpoint (request_url )
1517
18+ # Ask the user for endpoint if not present in request_url
1619 if not (has_endpoint ):
1720 if (request_url [- 1 ] == '/' ):
1821 endpoint = input ("Input endpoint (Without the starting slash): " )
@@ -22,6 +25,7 @@ def get_request(self):
2225
2326 print ("Trying ...\u26A1 " )
2427
28+ # Make GET request and store the response in response_data.json
2529 try :
2630 response = requests .get (request_url )
2731 print (f"Reponse Status Code: { response .status_code } " )
@@ -34,6 +38,12 @@ def get_request(self):
3438 except Exception as e :
3539 print (e )
3640
41+ # This method works by first checking whether the url is a localhost url
42+ # If it is, the length of the substring after ':' (Example, 127.0.0.1:8000) is checked
43+ # The length should be less than 6 as either 8000 or 8000/ can be possible (No endpoint)
44+ # If the url is not a localhost url
45+ # The length of the substring after '.' is checked
46+ # The length should be less than 5 (Example: com/, com, io/, io) (For no endpoint)
3747 def check_endpoint (url ):
3848 check_string = url
3949 is_localhost_url = False
You can’t perform that action at this time.
0 commit comments