-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreq.py
More file actions
99 lines (86 loc) · 2.63 KB
/
req.py
File metadata and controls
99 lines (86 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import requests
PORT = 1028
URL = f"http://127.0.0.1:{PORT}"
def main():
while True:
try:
status = int(input(
"Enter 1 for get()\n"
"2 for post()\n"
"3 for put()\n"
"4 for delete()\n"
"5 for patch()\n"
"6 for head()\n"
"7 for options()\n"
"8 to quit\n"
"> "
))
match status:
case 1:
get()
case 2:
post()
case 3:
put()
case 4:
delete()
case 5:
patch()
case 6:
head()
case 7:
options()
case 8:
print("Exiting.")
break
case _:
print("Invalid input.")
except ValueError:
print("Please enter a valid integer.")
def get():
print("==+ GET +==")
r = requests.get(URL)
print(f"==+ Status: {r.status_code} +==")
print(f"==+ Headers: {r.headers} +==")
print(f"==+ Body: {r.text} +==")
def post():
print("==+ POST +==")
payload = {"msg": "hello from POST"}
r = requests.post(URL, json=payload)
print(f"==+ Status: {r.status_code} +==")
print(f"==+ Headers: {r.headers} +==")
print(f"==+ Body: {r.text} +==")
def put():
print("==+ PUT +==")
payload = {"msg": "hello from PUT"}
r = requests.put(URL, json=payload)
print(f"==+ Status: {r.status_code} +==")
print(f"==+ Headers: {r.headers} +==")
print(f"==+ Body: {r.text} +==")
def delete():
print("==+ DELETE +==")
r = requests.delete(URL)
print(f"==+ Status: {r.status_code} +==")
print(f"==+ Headers: {r.headers} +==")
print(f"==+ Body: {r.text} +==")
def patch():
print("==+ PATCH +==")
payload = {"msg": "hello from PATCH"}
r = requests.patch(URL, json=payload)
print(f"==+ Status: {r.status_code} +==")
print(f"==+ Headers: {r.headers} +==")
print(f"==+ Body: {r.text} +==")
def head():
print("==+ HEAD +==")
r = requests.head(URL)
print(f"==+ Status: {r.status_code} +==")
print(f"==+ Headers: {r.headers} +==")
print(f"==+ Body: {r.text} +==") # r.text usually empty for HEAD
def options():
print("==+ OPTIONS +==")
r = requests.options(URL)
print(f"==+ Status: {r.status_code} +==")
print(f"==+ Headers: {r.headers} +==")
print(f"==+ Body: {r.text} +==")
if __name__ == "__main__":
main()