-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp-request.js
More file actions
50 lines (40 loc) · 1.07 KB
/
http-request.js
File metadata and controls
50 lines (40 loc) · 1.07 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
/**
* Base module for the Http request handler
* http-request.js
*
* 2017 @krescruz http://github.com/krescruz
* @license http://opensource.org/licenses/MIT MIT License
*/
(function($) {
var CONTENT_TYPE_DEFAULT = 'application/json; charset=utf-8';
var METHODS = {
'GET': 'GET',
'POST': 'POST',
};
function service() {
return {
'get': httpGet,
'post': httpPost,
'put': httpPut,
'path': httpPatch,
'delete': httpDelete,
};
}
function httpGet(url, data) {
return ajax({ 'url': url, 'data': data, 'method': METHODS.GET });
}
function httpPost(url) {
return ajax({ 'url': url, 'data': data, 'method': METHODS.POST });
}
function httpPut() {}
function httpPatch() {}
function httpDelete() {}
function ajax(config) {
return $.ajax({
'url': config.url,
'method': config.method,
'data': config.data,
'contentType': CONTENT_TYPE_DEFAULT
});
}
})(jQuery);