src/lib/stack-internal.js
function cozyFetchJSON(cozy, method, path, body) {
  const requestOptions = Object.assign({}, fetchOptions(), {
    method
  })
  requestOptions.headers['Accept'] = 'application/json'
  if (method !== 'GET' && method !== 'HEAD' && body !== undefined) {
    if (requestOptions.headers['Content-Type']) {
      requestOptions.body = body
    } else {
      requestOptions.headers['Content-Type'] = 'application/json'
      requestOptions.body = JSON.stringify(body)
    }
  }
  return fetchJSON(`${COZY_URL}${path}`, requestOptions).then(json => {
    const responseData = Object.assign({}, json.data)
    if (responseData.id) responseData._id = responseData.id
    return Promise.resolve(responseData)
  })
}
function cozyFetchJSON(cozy, method, path, body) {
  const requestOptions = Object.assign({}, fetchOptions(), {
    method
  })
  requestOptions.headers['Accept'] = 'application/json'
  if (method !== 'GET' && method !== 'HEAD' && body !== undefined) {
    if (requestOptions.headers['Content-Type']) {
      requestOptions.body = body
    } else {
      requestOptions.headers['Content-Type'] = 'application/json'
      requestOptions.body = JSON.stringify(body)
    }
  }
  return fetchJSON(`${COZY_URL}${path}`, requestOptions).then(json => {
    const responseData = Object.assign({}, json.data)
    if (responseData.id) responseData._id = responseData.id
    return Promise.resolve(responseData)
  })
}
function cozyFetchJSON ( cozy , method , path , body ) { const requestOptions = Object . assign ( { } , fetchOptions ( ) , { method } ) requestOptions . headers [ 'Accept' ] = 'application/json' if ( method !== 'GET' && method !== 'HEAD' && body !== undefined ) { if ( requestOptions . headers [ 'Content-Type' ] ) { requestOptions . body = body } else { requestOptions . headers [ 'Content-Type' ] = 'application/json' requestOptions . body = JSON . stringify ( body ) } } return fetchJSON ( ` ${ COZY_URL } ${ path } ` , requestOptions ) . then ( json => { const responseData = Object . assign ( { } , json . data ) if ( responseData . id ) responseData . _id = responseData . id return Promise . resolve ( responseData ) } ) }
fetch function with the same interface than in cozy-client-js
fetch function with the same interface than in cozy - client - js