Skip to content

Commit 8bc1a5d

Browse files
committed
Add delete endpoint
1 parent 747b547 commit 8bc1a5d

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
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+
57+
5358
parser.add_argument("-p",
5459
"--playbook",
5560
help="View and organise the playbook",

src/arguments/api_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,53 @@ def get_request(cls):
6060
except Exception as e:
6161
print(e)
6262

63+
@classmethod
64+
def delete_endpoint_request(cls):
65+
request_url = cls.default_url
66+
request_headers = cls.default_headers
67+
input_url = input('Enter URL: ')
68+
input_headers = input('Enter Headers: ')
69+
if input_url != '':
70+
request_url = input_url
71+
if input_headers != '':
72+
try:
73+
request_headers = json.loads(input_headers)
74+
except Exception:
75+
print("Failed to parse Input Headers")
76+
# Check whether the request_url has an endpoint or not
77+
has_endpoint = cls.__check_endpoint(request_url)
78+
79+
# Check if http:// or https:// is present in request_url
80+
has_protocol = cls.__check_protocol(request_url)
81+
82+
if not(has_protocol):
83+
request_url = "https://" + request_url
84+
85+
# Ask the user for endpoint if not present in request_url
86+
if not(has_endpoint):
87+
if(request_url[-1] == '/'):
88+
endpoint = input("Input endpoint " +
89+
"(Without the starting slash): ")
90+
else:
91+
endpoint = input("Input endpoint (With the starting slash): ")
92+
request_url += endpoint
93+
94+
print("Trying ...\u26A1")
95+
try:
96+
response = requests.delete(request_url, headers=request_headers)
97+
print(f"Reponse Status Code: {response.status_code}")
98+
response_data = json.loads(response.content)
99+
parsed_json = json.dumps(response_data, indent=4)
100+
output_json = highlight(parsed_json, lexers.JsonLexer(),
101+
formatters.TerminalFormatter())
102+
print(output_json)
103+
104+
except requests.exceptions.InvalidSchema:
105+
print("Check whether the URL is valid or check if " +
106+
"the localhost server is active or not")
107+
except Exception as e:
108+
print(e)
109+
63110
@classmethod
64111
def __check_endpoint(cls, request_url):
65112
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)