@@ -8,19 +8,17 @@ const safeMethods = new Set(['GET', 'HEAD', 'OPTIONS', 'TRACE']);
8
8
// fetch wrapper, use below method name functions and the `data` option to pass in data
9
9
// which will automatically set an appropriate headers. For json content, only object
10
10
// and array types are currently supported.
11
- export function request ( url , { method = 'GET' , headers = { } , data, body, ...other } = { } ) {
12
- let contentType ;
13
- if ( ! body ) {
14
- if ( data instanceof FormData || data instanceof URLSearchParams ) {
15
- body = data ;
16
- } else if ( isObject ( data ) || Array . isArray ( data ) ) {
17
- contentType = 'application/json' ;
18
- body = JSON . stringify ( data ) ;
19
- }
11
+ export function request ( url , { method = 'GET' , data, headers = { } , ...other } = { } ) {
12
+ let body , contentType ;
13
+ if ( data instanceof FormData || data instanceof URLSearchParams ) {
14
+ body = data ;
15
+ } else if ( isObject ( data ) || Array . isArray ( data ) ) {
16
+ contentType = 'application/json' ;
17
+ body = JSON . stringify ( data ) ;
20
18
}
21
19
22
20
const headersMerged = new Headers ( {
23
- ...( ! safeMethods . has ( method . toUpperCase ( ) ) && { 'x-csrf-token' : csrfToken } ) ,
21
+ ...( ! safeMethods . has ( method ) && { 'x-csrf-token' : csrfToken } ) ,
24
22
...( contentType && { 'content-type' : contentType } ) ,
25
23
} ) ;
26
24
@@ -31,8 +29,8 @@ export function request(url, {method = 'GET', headers = {}, data, body, ...other
31
29
return fetch ( url , {
32
30
method,
33
31
headers : headersMerged ,
34
- ...( body && { body} ) ,
35
32
...other ,
33
+ ...( body && { body} ) ,
36
34
} ) ;
37
35
}
38
36
0 commit comments