Skip to content

Commit 7e38906

Browse files
committed
Add DELETE endpoint
1 parent 747b547 commit 7e38906

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
help="Make a GET request to an API",
5151
action='store_true')
5252

53+
parser.add_argument("-DELETE",
54+
help = "Make a DELETE request to an API",
55+
action = 'store_true')
56+
5357
parser.add_argument("-p",
5458
"--playbook",
5559
help="View and organise the playbook",

src/arguments/api_test.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 __check_endpoint(cls, request_url):
65118
if(request_url == cls.default_url):

src/arguments/search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def search_args(self):
5454
update.check_for_updates()
5555
elif self.arguments.GET:
5656
self.api_test_object.get_request()
57+
elif self.arguments.DELETE:
58+
self.api_test_object.delete_endpoint_request()
5759
elif self.arguments.notion:
5860
NotionClient().get_tokenv2_cookie()
5961

0 commit comments

Comments
 (0)