@@ -6,67 +6,145 @@ typeset ResponseCallback
66 /* *
77 * Function called when an HTTP response is received
88 *
9- * @param http HTTP request object
10- * @param body Response body
11- * @param statusCode HTTP status code
12- * @param bodySize Size of the response body
9+ * @param http HTTP request object
10+ * @param body Response body
11+ * @param statusCode HTTP status code
12+ * @param bodySize Size of the response body
13+ * @param value Value passed to the HTTP method
1314 */
14- function void (HttpRequest http , const char [] body , int statusCode , int bodySize );
15+ function void (HttpRequest http , const char [] body , int statusCode , int bodySize , any value );
1516}
1617
17- // Define a methodmap for HttpRequest, which extends Handle
1818methodmap HttpRequest < Handle
1919{
2020 /* *
2121 * Create a new HTTP request
2222 *
23- * @param url Request URL
24- * @param method HTTP method (default is "GET")
23+ * @param url Request URL
2524 */
26- public native HttpRequest (const char [] url , const char [] method = " GET " );
25+ public native HttpRequest (const char [] url );
2726
2827 /* *
29- * Set the callback for when an HTTP response is received
28+ * Performs a GET request
29+ * GET requests should not have a body, only query parameters in URL
3030 *
31- * @param fResponse Function to call when an HTTP response is received
31+ * @param fResponse Function to call when an HTTP response is received
32+ * @param value Value to pass to the callback
33+ * @return True if the request was sent successfully, false otherwise
3234 */
33- public native void SetResponseCallback (ResponseCallback fResponse );
35+ public native bool Get (ResponseCallback fResponse , any value = 0 );
3436
3537 /* *
36- * Perform the HTTP request
38+ * Performs a POST request with JSON body
39+ * POST requests typically send data to create a new resource
40+ *
41+ * @param json JSON data to send in request body
42+ * @param fResponse Function to call when an HTTP response is received
43+ * @param value Value to pass to the callback
44+ * @return True if the request was sent successfully, false otherwise
45+ */
46+ public native bool PostJson (const YYJSON json , ResponseCallback fResponse , any value = 0 );
47+
48+ /* *
49+ * Performs a POST request with accumulated form parameters
50+ * Uses application/x-www-form-urlencoded format
51+ *
52+ * @param fResponse Function to call when an HTTP response is received
53+ * @param value Value to pass to the callback
54+ * @return True if the request was sent successfully, false otherwise
55+ */
56+ public native bool PostForm (ResponseCallback fResponse , any value = 0 );
57+
58+ /* *
59+ * Performs a PUT request with JSON body
60+ * PUT requests typically update an entire resource
61+ *
62+ * @param json JSON data to send in request body
63+ * @param fResponse Function to call when an HTTP response is received
64+ * @param value Value to pass to the callback
65+ * @return True if the request was sent successfully, false otherwise
66+ */
67+ public native bool PutJson (const YYJSON json , ResponseCallback fResponse , any value = 0 );
68+
69+ /* *
70+ * Performs a PATCH request with JSON body
71+ * PATCH requests typically perform partial updates to a resource
72+ *
73+ * @param json JSON data containing the fields to update
74+ * @param fResponse Function to call when an HTTP response is received
75+ * @param value Value to pass to the callback
76+ * @return True if the request was sent successfully, false otherwise
77+ */
78+ public native bool PatchJson (const YYJSON json , ResponseCallback fResponse , any value = 0 );
79+
80+ /* *
81+ * Performs a DELETE request
82+ * DELETE requests typically don't have a body
83+ *
84+ * @param fResponse Function to call when an HTTP response is received
85+ * @param value Value to pass to the callback
86+ * @return True if the request was sent successfully, false otherwise
3787 */
38- public native void Perform ( );
88+ public native bool Delete ( ResponseCallback fResponse , any value = 0 );
3989
4090 /* *
41- * Set the body of the HTTP request
91+ * Append a form parameter to the request
92+ * Multiple calls will accumulate parameters for the next form submission
4293 *
43- * @param body Body of the request
94+ * @param key Parameter key
95+ * @param value Parameter value
96+ * @return True if parameter was added successfully
4497 */
45- public native void SetBody (const char [] body );
98+ public native bool AppendFormParam (const char [] key , const char [] value );
4699
47100 /* *
48101 * Add a header to the HTTP request
49102 *
50- * @param key Header key
51- * @param value Header value
103+ * @param key Header key
104+ * @param value Header value
52105 */
53106 public native void AddHeader (const char [] key , const char [] value );
54107
55108 /* *
56- * Get a header from the HTTP request
109+ * Get a response header from the HTTP request
57110 *
58- * @param key Header key
59- * @param value Buffer to store the header value
60- * @param maxLength Maximum length of the value buffer
61- * @return True if the header was found, false otherwise
111+ * @param key Header key
112+ * @param value Buffer to store the header value
113+ * @param maxLength Maximum length of the value buffer
114+ * @return True if the header was found, false otherwise
62115 */
63- public native bool GetHeader (const char [] key , char [] value , int maxLength );
116+ public native bool GetResponseHeader (const char [] key , char [] value , int maxLength );
64117
65118 /* *
66- * Check if a header exists in the HTTP request
119+ * Check if a response header exists in the HTTP request
67120 *
68- * @param key Header key
69- * @return True if the header exists, false otherwise
121+ * @param key Header key
122+ * @return True if the header exists, false otherwise
70123 */
71- public native bool HasHeader (const char [] key );
124+ public native bool HasResponseHeader (const char [] key );
125+
126+ property int Timeout {
127+ public native get ();
128+ public native set (int timeout );
129+ }
130+
131+ property bool FollowRedirect {
132+ public native get ();
133+ public native set (bool follow );
134+ }
135+
136+ property bool Compression {
137+ public native get ();
138+ public native set (bool compress );
139+ }
140+
141+ property int MaxRedirects {
142+ public native get ();
143+ public native set (int maxRedirects );
144+ }
145+
146+ property bool Verbose {
147+ public native get ();
148+ public native set (bool verbose );
149+ }
72150}
0 commit comments