The difference between Promise and fetch encapsulating API requests

for example, I need to encapsulate a function that gets the user"s ID

 getUserIds().then((ids) => {console.log(ids)})

// promise
const getUserIds = () => {
   return new Promise(resolve){
   // 
   setTimeout(() => { resolve([1,2,3]) })
}
}
// fetch
const getUserIds = () {
  return fetch(URL, CONFIG)
}

what"s the difference in encapsulating interface functions with promise or fetch?

Feb.27,2021

there is a lot of talk upstairs, and there is no difference.

but there is a problem with the problem itself. Promise has nothing to do with fetch and cannot be compared together. Fetch is a substitute for the original XMLHttpRequest object, which implements the Promise specification and returns Promise instances, while Promise is a set of solutions to solve the problem of asynchronous callbacks.


makes no difference. They all return promise, one is encapsulated by the browser, the other is implemented by themselves


Fetch is based on standard Promise, it is convenient to support async/await
isomorphism, and use isomorphic-fetch

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b33cd9-e411.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b33cd9-e411.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?