-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_methods.js.html
293 lines (241 loc) · 27.9 KB
/
http_methods.js.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>http/methods.js - eXir</title>
<meta name="description" content="Javascript Library" />
<meta property="og:title" content=""/>
<meta property="og:type" content="website"/>
<meta property="og:image" content=""/>
<meta property="og:url" content=""/>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<input type="text" id="nav-search" placeholder="Search" />
<h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/kasra-sh/exir" target="_blank" class="menu-item" id="website_link" >Project Website</a></h2><h3>Tutorials</h3><ul><li><a href="tutorial-t00_introduction.html">Introduction</a></li><li><a href="tutorial-t01_installation.html">Installation</a></li><li><a href="tutorial-t02_getting_started.html">Getting Started</a></li><li><a href="tutorial-t03_core.html">Core module</a></li></ul><h3>Modules</h3><ul><li><a href="core.module_core_cases.html">core/cases</a><ul class='methods'><li data-type='method' style='display: none;'><a href="core.module_core_cases.html#.kebab">kebab</a></li><li data-type='method' style='display: none;'><a href="core.module_core_cases.html#.snake">snake</a></li><li data-type='method' style='display: none;'><a href="core.module_core_cases.html#.camel">camel</a></li><li data-type='method' style='display: none;'><a href="core.module_core_cases.html#.pascal">pascal</a></li></ul></li><li><a href="core.module_core_collections.html">core/collections</a><ul class='methods'><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~item">item</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~contains">contains</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~add">add</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~remove">remove</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~toggle">toggle</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~emptyOf">emptyOf</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~concat">concat</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~objectValues">objectValues</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~forN">forN</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~forEachRange">forEachRange</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~forEach">forEach</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~forEachRight">forEachRight</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~firstIndex">firstIndex</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~first">first</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~startsWith">startsWith</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~lastIndex">lastIndex</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~last">last</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~endsWith">endsWith</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~reverse">reverse</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~any">any</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~all">all</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~filter">filter</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~omit">omit</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~filterRight">filterRight</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~maxIndex">maxIndex</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~max">max</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~minIndex">minIndex</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~min">min</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~map">map</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~flatMap">flatMap</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~reduce">reduce</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~reduceRight">reduceRight</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~keyValuePairs">keyValuePairs</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~entries">entries</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~translateObject">translateObject</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~deepMerge">deepMerge</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~deepClone">deepClone</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~join">join</a></li><li data-type='method' style='display: none;'><a href="core.module_core_collections.html#~groupBy">groupBy</a></li></ul></li><li><a href="core.module_core_functions.html">core/functions</a><ul class='methods'><li data-type='method' style='display: none;'><a href="core.module_core_functions.html#~funcBodyEquals">funcBodyEquals</a></li><li data-type='method' style='display: none;'><a href="core.module_core_functions.html#~throttle">throttle</a></li><li data-type='method' style='display: none;'><a href="core.module_core_functions.html#~debounce">debounce</a></li><li data-type='method' style='display: none;'><a href="core.module_core_functions.html#~bindArgs">bindArgs</a></li></ul></li><li><a href="core.module_core_logging.html">core/logging</a><ul class='methods'><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~showTrace">showTrace</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~showInfo">showInfo</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~showWarn">showWarn</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~showError">showError</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~silent">silent</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~lvl">lvl</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~trace">trace</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~info">info</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~warn">warn</a></li><li data-type='method' style='display: none;'><a href="core.module_core_logging.html#~error">error</a></li></ul></li><li><a href="core.module_core_strings.html">core/strings</a><ul class='methods'><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~isDecimal">isDecimal</a></li><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~isBinary">isBinary</a></li><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~isOctal">isOctal</a></li><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~isHex">isHex</a></li><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~isEmail">isEmail</a></li><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~startsWith">startsWith</a></li><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~endsWith">endsWith</a></li><li data-type='method' style='display: none;'><a href="core.module_core_strings.html#~contains">contains</a></li></ul></li><li><a href="core.module_core_types.html">core/types</a><ul class='methods'><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~typeName">typeName</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isUnd">isUnd</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isNull">isNull</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isVal">isVal</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isNum">isNum</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isStr">isStr</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isFun">isFun</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isObj">isObj</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isArr">isArr</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isPrim">isPrim</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isList">isList</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isMutableList">isMutableList</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isSet">isSet</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isMap">isMap</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isError">isError</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isEl">isEl</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isEls">isEls</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~hasField">hasField</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~isEmpty">isEmpty</a></li><li data-type='method' style='display: none;'><a href="core.module_core_types.html#~dict">dict</a></li></ul></li><li><a href="http.module_http_ajax.html">http/ajax</a></li><li><a href="http.module_http_client.html">http/client</a></li><li><a href="module-http_methods.html">http/methods</a><ul class='methods'><li data-type='method' style='display: none;'><a href="module-http_methods.html#~makeRequest">makeRequest</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~sendRequest">sendRequest</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~Get">Get</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~Post">Post</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~Delete">Delete</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~Put">Put</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~Patch">Patch</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~sendGet">sendGet</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~sendDelete">sendDelete</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~sendPost">sendPost</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~sendPut">sendPut</a></li><li data-type='method' style='display: none;'><a href="module-http_methods.html#~sendPatch">sendPatch</a></li></ul></li><li><a href="dom.module_DOM.html">DOM</a><ul class='methods'><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~append">append</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~getAttributes">getAttributes</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~hasAttr">hasAttr</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~getAttr">getAttr</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~setAttr">setAttr</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~attrs">attrs</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~cls">cls</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~addClass">addClass</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~removeClass">removeClass</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~hasClass">hasClass</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~toggleClass">toggleClass</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~setEvent">setEvent</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~clearEvent">clearEvent</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~hasEvent">hasEvent</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~patch">patch</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~relLeft">relLeft</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~absLeft">absLeft</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~relWidth">relWidth</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~absWidth">absWidth</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~relRight">relRight</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~absRight">absRight</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~relTop">relTop</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~absTop">absTop</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~relHeight">relHeight</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~absHeight">absHeight</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~relBottom">relBottom</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~absBottom">absBottom</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~$">$</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~$$">$$</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~queryOf">queryOf</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~style">style</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~hasStyle">hasStyle</a></li><li data-type='method' style='display: none;'><a href="dom.module_DOM.html#~parseQuery">parseQuery</a></li></ul></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul><h3>Namespaces</h3><ul><li><a href="core.html">core</a></li><li><a href="http.html">http</a></li><li><a href="dom.html">dom</a></li></ul><h3>Classes</h3><ul><li><a href="core.Extension.html">Extension</a><ul class='methods'><li data-type='method' style='display: none;'><a href="core.Extension.html#define">define</a></li></ul></li><li><a href="core.module_core_types-Enum.html">Enum</a></li><li><a href="http.module_http_ajax-Ajax.html">Ajax</a><ul class='methods'><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#header">header</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#headers">headers</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#onSuccess">onSuccess</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#onUploadSuccess">onUploadSuccess</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#onFail">onFail</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#onProgress">onProgress</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#onUploadProgress">onUploadProgress</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#withContent">withContent</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#xmlData">xmlData</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#formData">formData</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#jsonData">jsonData</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#urlEncodedData">urlEncodedData</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#send">send</a></li><li data-type='method' style='display: none;'><a href="http.module_http_ajax-Ajax.html#sendAsync">sendAsync</a></li></ul></li><li><a href="http.module_http_client-XHttpClient.html">XHttpClient</a><ul class='methods'><li data-type='method' style='display: none;'><a href="http.module_http_client-XHttpClient.html#send">send</a></li><li data-type='method' style='display: none;'><a href="http.module_http_client-XHttpClient.html#get">get</a></li><li data-type='method' style='display: none;'><a href="http.module_http_client-XHttpClient.html#post">post</a></li><li data-type='method' style='display: none;'><a href="http.module_http_client-XHttpClient.html#put">put</a></li><li data-type='method' style='display: none;'><a href="http.module_http_client-XHttpClient.html#patch">patch</a></li><li data-type='method' style='display: none;'><a href="http.module_http_client-XHttpClient.html#delete">delete</a></li><li data-type='method' style='display: none;'><a href="http.module_http_client-XHttpClient.html#cancel">cancel</a></li></ul></li><li><a href="http.HttpContent.html">HttpContent</a></li><li><a href="http.HttpRq.html">HttpRq</a><ul class='methods'><li data-type='method' style='display: none;'><a href="http.HttpRq.html#setMethod">setMethod</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#setUrl">setUrl</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#setArg">setArg</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#setHeader">setHeader</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#getHeader">getHeader</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#setContent">setContent</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#jsonContent">jsonContent</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#xmlContent">xmlContent</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#formContent">formContent</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#formMultiPartContent">formMultiPartContent</a></li><li data-type='method' style='display: none;'><a href="http.HttpRq.html#formUrlEncodedContent">formUrlEncodedContent</a></li></ul></li><li><a href="http.HttpRs.html">HttpRs</a></li><li><a href="dom.Attributes.html">Attributes</a><ul class='methods'><li data-type='method' style='display: none;'><a href="dom.Attributes.html#keys">keys</a></li><li data-type='method' style='display: none;'><a href="dom.Attributes.html#all">all</a></li><li data-type='method' style='display: none;'><a href="dom.Attributes.html#set">set</a></li><li data-type='method' style='display: none;'><a href="dom.Attributes.html#get">get</a></li><li data-type='method' style='display: none;'><a href="dom.Attributes.html#has">has</a></li><li data-type='method' style='display: none;'><a href="dom.Attributes.html#remove">remove</a></li></ul></li><li><a href="dom.Classes.html">Classes</a><ul class='methods'><li data-type='method' style='display: none;'><a href="dom.Classes.html#.split">split</a></li><li data-type='method' style='display: none;'><a href="dom.Classes.html#.of">of</a></li><li data-type='method' style='display: none;'><a href="dom.Classes.html#contains">contains</a></li><li data-type='method' style='display: none;'><a href="dom.Classes.html#add">add</a></li><li data-type='method' style='display: none;'><a href="dom.Classes.html#remove">remove</a></li><li data-type='method' style='display: none;'><a href="dom.Classes.html#toggle">toggle</a></li></ul></li><li><a href="dom.module_DOM-QueryParams.html">QueryParams</a></li></ul><h3>Global</h3><ul><li><a href="global.html#HttpMethod">HttpMethod</a></li><li><a href="global.html#HttpRequestOptions">HttpRequestOptions</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">http/methods.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @fileOverview
*
* @module http/methods
* @memberOf http
*/
const {Ajax} = require("./ajax");
const {HttpContent} = require("./request");
/**
* A factory for {@link http.Ajax}
* @private
* @param {HttpMethod} method - {@link HttpMethod}
* @param {String} url
* @param {Object} params
* @param {Object} headers
* @param {HttpContent} content
* @param {Object} callbacks - {success:Function?, fail: Function?, progress: Function?, prepare: Function?,uploadProgress: Function?, uploadFinish: Function?}
* @return {http.Ajax}
*/
function makeHttpRequest(method, url, params, headers, content, callbacks) {
let ajax = new Ajax(method.toUpperCase(), url, params, headers);
if (content && content.type) {
if (content.type.toLowerCase() === 'json') {
ajax.jsonData(content.data);
} else if (content.type.toLowerCase() === 'urlencoded') {
ajax.urlEncodedData(content.data);
} else if (content.type.toLowerCase() === 'form') {
ajax.formData(content.data);
} else {
ajax.Rq.setContent(content.type, content.data);
}
}
callbacks.success && ajax.onSuccess(callbacks.success);
callbacks.fail && ajax.onFail(callbacks.fail);
callbacks.progress && ajax.onProgress(callbacks.progress);
callbacks.prepare && (ajax.preparedCallback = callbacks.prepare);
callbacks.uploadProgress && (ajax.uploadProgressCallback = callbacks.uploadProgress);
callbacks.uploadFinish && (ajax.uploadFinishCallback = callbacks.uploadFinish);
return ajax;
}
//{method, url, args, headers, type, data, success, fail, progress, prepare, uploadProgress, uploadFinish}
/**
* A factory for {@link http.Ajax}. creates Ajax request with supplied {@link HttpRequestOptions}
*
* @param {HttpRequestOptions} opts
* @return {http.Ajax}
*/
function makeRequest(opts) {
return makeHttpRequest(opts.method || 'OPTIONS', opts.url, opts.params, opts.headers, new HttpContent(opts.type, opts.data), {
success: opts.success,
fail: opts.fail,
progress: opts.progress,
prepare: opts.prepare,
uploadProgress: opts.uploadProgress,
uploadFinish: opts.uploadFinish
})
}
/**
* @private
* @param {http.Ajax} r - Ajax request
* @param {Function} resolved - resolved callback
* @param {array<any>} params - passed to resolved callback
* @returns {Promise<Ajax>}
*/
function makePromise(r, resolved = null, params = null) {
return new Promise((res, rej) => {
r.onSuccess(()=>{
if (resolved)
try {
resolved(params);
} catch (e) {}
return res(r)
});
r.onFail(()=>rej(r));
})
}
/**
* Send request asynchronously
*
* @param {HttpRequestOptions} opts
* @return {Promise<any>}
*/
async function sendRequest(opts) {
let r = makeRequest(opts);
r.send(opts.finish);
return await makePromise(r);
}
/**
* Create Ajax GET request
*
* @param {String} url - server url
* @param {Object} [params] - query string params
* @returns {http.Ajax}
*/
function Get(url, params){
return new Ajax('GET', url, params);
}
/**
* Create Ajax POST request
*
* @param {String} url - server url
* @param {Object} [params] - query string params
*/
function Post(url, params){
return new Ajax('POST', url, params);
}
/**
* Create Ajax DELETE request
*
* @param {String} url - server url
* @param {Object} params - query string params
* @returns {http.Ajax}
*/
function Delete(url, params){
return new Ajax('DELETE', url, params);
}
/**
* Create Ajax PUT request
*
* @param {String} url - server url
* @param {Object} params - query string params
* @returns {Ajax}
*/
function Put(url, params){
return new Ajax('PUT', url, params);
}
/**
* Create Ajax PATCH request
*
* @param {String} url - server url
* @param {Object} params - query string params
* @returns {http.Ajax}
*/
function Patch(url, params){
return new Ajax('PATCH', url, params);
}
/**
* Create and send GET request
*
* @param {HttpRequestOptions} opt
* @return {Promise<http.Ajax>}
*/
function sendGet(opt) {
opt.method = 'GET';
opt.type = undefined;
opt.data = undefined;
return sendRequest(opt)
}
/**
* Create and send DELETE request
*
* @param {HttpRequestOptions} opt
* @return {Promise<http.Ajax>}
*/
function sendDelete(opt) {
opt.method = 'DELETE';
return sendRequest(opt)
}
/**
* Create and send POST request
*
* @param {HttpRequestOptions} opt
* @return {Promise<http.Ajax>}
*/
function sendPost(opt) {
opt.method = 'POST';
return sendRequest(opt)
}
/**
* Create and send PUT request
*
* @param {HttpRequestOptions} opt
* @return {Promise<http.Ajax>}
*/
function sendPut(opt) {
opt.method = 'PUT';
return sendRequest(opt)
}
/**
* Create and send PATCH request
*
* @param {HttpRequestOptions} opt
* @return {Promise<http.Ajax>}
*/
function sendPatch(opt) {
opt.method = 'PATCH';
return sendRequest(opt)
}
module.exports = {
makeHttpRequest, makeRequest, makePromise, sendRequest,
Get, Post, Delete, Put, Patch,
sendGet, sendDelete, sendPost, sendPut, sendPatch
};</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/search.js" defer></script>
<script src="scripts/collapse.js" defer></script>
</body>
</html>