@@ -9,39 +9,55 @@ def __init__(self, parent):
9
9
ctk .set_default_color_theme ("blue" )
10
10
self .root = parent
11
11
self .root .title ("HTTP Client" )
12
- self .root .geometry ("600x550" )
12
+ self .root .geometry ("700x650" ) # Aumentar tamaño para historial
13
13
self .root .grid_columnconfigure (1 , weight = 1 )
14
14
15
+ # Estilo general
16
+ font_style = ("Arial" , 14 )
17
+
18
+ # Historial de solicitudes
19
+ self .history = []
20
+
15
21
# URL
16
- ctk .CTkLabel (parent , text = "URL:" ).grid (row = 0 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
17
- self .url_entry = ctk .CTkEntry (parent , width = 400 )
22
+ ctk .CTkLabel (parent , text = "🌐 URL:" , font = font_style ).grid (row = 0 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
23
+ self .url_entry = ctk .CTkEntry (parent , width = 500 , font = font_style )
18
24
self .url_entry .grid (row = 0 , column = 1 , padx = 10 , pady = 5 , sticky = "ew" )
19
25
20
26
# Method
21
- ctk .CTkLabel (parent , text = "Method:" ).grid (row = 1 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
27
+ ctk .CTkLabel (parent , text = "📡 Method:" , font = font_style ).grid (row = 1 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
22
28
self .method_var = ctk .StringVar (value = "GET" )
23
- self .method_menu = ctk .CTkOptionMenu (parent , variable = self .method_var , values = ["GET" , "POST" , "PUT" , "DELETE" , "HEAD" , "OPTIONS" , "CONNECT" , "TRACE" , "LINK" , "UNLINK" , "CUSTOM" ], command = self .toggle_body_state )
29
+ self .method_menu = ctk .CTkOptionMenu (parent , variable = self .method_var ,
30
+ values = ["GET" , "POST" , "PUT" , "DELETE" , "HEAD" , "OPTIONS" , "CONNECT" , "TRACE" , "LINK" , "UNLINK" , "CUSTOM" ],
31
+ command = self .toggle_body_state , font = font_style )
24
32
self .method_menu .grid (row = 1 , column = 1 , padx = 10 , pady = 5 , sticky = "ew" )
25
33
26
34
# Headers
27
- ctk .CTkLabel (parent , text = "Headers (JSON):" ).grid (row = 2 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
28
- self .headers_entry = ctk .CTkEntry (parent , width = 400 )
35
+ ctk .CTkLabel (parent , text = "📝 Headers (JSON):" , font = font_style ).grid (row = 2 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
36
+ self .headers_entry = ctk .CTkTextbox (parent , width = 500 , height = 60 , font = font_style )
29
37
self .headers_entry .grid (row = 2 , column = 1 , padx = 10 , pady = 5 , sticky = "ew" )
30
38
31
39
# Body
32
- ctk .CTkLabel (parent , text = "Body (JSON):" ).grid (row = 3 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
33
- self .body_text = ctk .CTkTextbox (parent , width = 400 , height = 100 )
40
+ ctk .CTkLabel (parent , text = "📦 Body (JSON):" , font = font_style ).grid (row = 3 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
41
+ self .body_text = ctk .CTkTextbox (parent , width = 500 , height = 100 , font = font_style )
34
42
self .body_text .grid (row = 3 , column = 1 , padx = 10 , pady = 5 , sticky = "ew" )
35
43
36
44
# Send Button
37
- self .send_button = ctk .CTkButton (parent , text = "Send" , command = self .send_request )
38
- self .send_button .grid (row = 4 , column = 1 , pady = 10 )
45
+ self .send_button = ctk .CTkButton (parent , text = "🚀 Send Request " , command = self .send_request , font = font_style )
46
+ self .send_button .grid (row = 4 , column = 1 , pady = 15 )
39
47
40
48
# Response
41
- ctk .CTkLabel (parent , text = "Response:" ).grid (row = 5 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
42
- self .response_text = ctk .CTkTextbox (parent , width = 400 , height = 150 , state = "disabled" )
49
+ ctk .CTkLabel (parent , text = "📩 Response:" , font = font_style ).grid (row = 5 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
50
+ self .response_text = ctk .CTkTextbox (parent , width = 500 , height = 200 , font = font_style , state = "disabled" )
43
51
self .response_text .grid (row = 5 , column = 1 , padx = 10 , pady = 5 , sticky = "ew" )
44
52
53
+ # Historial de solicitudes
54
+ ctk .CTkLabel (parent , text = "📜 Request History:" , font = font_style ).grid (row = 6 , column = 0 , padx = 10 , pady = 5 , sticky = "w" )
55
+ self .history_var = ctk .StringVar (value = "No history yet" )
56
+ self .history_menu = ctk .CTkOptionMenu (parent , variable = self .history_var , values = ["No history yet" ], font = font_style )
57
+ self .history_menu .grid (row = 6 , column = 1 , padx = 10 , pady = 5 , sticky = "ew" )
58
+ self .load_history_button = ctk .CTkButton (parent , text = "🔄 Load Request" , command = self .load_request , font = font_style )
59
+ self .load_history_button .grid (row = 7 , column = 1 , pady = 10 )
60
+
45
61
self .toggle_body_state ("GET" )
46
62
47
63
def toggle_body_state (self , method ):
@@ -55,29 +71,47 @@ def toggle_body_state(self, method):
55
71
def send_request (self ):
56
72
url = self .url_entry .get ()
57
73
method = self .method_var .get ()
58
- headers = self .headers_entry .get ()
74
+ headers = self .headers_entry .get ("1.0" , "end" ). strip ( )
59
75
body = self .body_text .get ("1.0" , "end" ).strip ()
60
-
76
+
61
77
try :
62
78
headers = json .loads (headers ) if headers else {}
63
79
except json .JSONDecodeError :
64
- messagebox .showerror ("Error" , "Headers must be valid JSON." )
80
+ messagebox .showerror ("Error" , "Headers must be valid JSON.\n Example: \n { \" Content-Type \" : \" application/json \" } " )
65
81
return
66
-
82
+
67
83
try :
68
84
body = json .loads (body ) if body else ""
69
85
except json .JSONDecodeError :
70
86
messagebox .showerror ("Error" , "Body must be valid JSON." )
71
87
return
72
-
88
+
73
89
try :
74
- response = client_cli .run_client (method , url , headers , body )
90
+ response_text = client_cli .run_client (method , url , headers , body )
91
+
92
+ # Guardar en historial
93
+ self .history .append ((url , method , json .dumps (headers , indent = 2 ), json .dumps (body , indent = 2 )))
94
+ self .history_menu .configure (values = [f"{ i + 1 } : { h [1 ]} { h [0 ]} " for i , h in enumerate (self .history )])
95
+ self .history_var .set (f"{ len (self .history )} : { method } { url } " )
96
+
75
97
self .response_text .configure (state = "normal" )
76
98
self .response_text .delete ("1.0" , "end" )
77
- self .response_text .insert ("end" , f"Status: { response [ 'status' ] } \n \n { response [ 'body' ] } " )
99
+ self .response_text .insert ("end" , response_text )
78
100
self .response_text .configure (state = "disabled" )
79
101
except Exception as e :
80
102
messagebox .showerror ("Error" , f"Request failed: { e } " )
103
+
104
+ def load_request (self ):
105
+ index = int (self .history_var .get ().split (":" )[0 ]) - 1
106
+ if 0 <= index < len (self .history ):
107
+ url , method , headers , body = self .history [index ]
108
+ self .url_entry .delete (0 , "end" )
109
+ self .url_entry .insert (0 , url )
110
+ self .method_var .set (method )
111
+ self .headers_entry .delete ("1.0" , "end" )
112
+ self .headers_entry .insert ("end" , headers )
113
+ self .body_text .delete ("1.0" , "end" )
114
+ self .body_text .insert ("end" , body )
81
115
82
116
if __name__ == "__main__" :
83
117
root = ctk .CTk ()
0 commit comments