@@ -8,19 +8,17 @@ const safeMethods = new Set(['GET', 'HEAD', 'OPTIONS', 'TRACE']);
88// fetch wrapper, use below method name functions and the `data` option to pass in data
99// which will automatically set an appropriate headers. For json content, only object
1010// 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 ) ;
2018 }
2119
2220 const headersMerged = new Headers ( {
23- ...( ! safeMethods . has ( method . toUpperCase ( ) ) && { 'x-csrf-token' : csrfToken } ) ,
21+ ...( ! safeMethods . has ( method ) && { 'x-csrf-token' : csrfToken } ) ,
2422 ...( contentType && { 'content-type' : contentType } ) ,
2523 } ) ;
2624
@@ -31,8 +29,8 @@ export function request(url, {method = 'GET', headers = {}, data, body, ...other
3129 return fetch ( url , {
3230 method,
3331 headers : headersMerged ,
34- ...( body && { body} ) ,
3532 ...other ,
33+ ...( body && { body} ) ,
3634 } ) ;
3735}
3836
0 commit comments