Refactoring API call with promise using async/await

Michael S
1 min readDec 31, 2018

API call using async/await

  1. Using promise

2. Using async/await

async onSearchSubmit(term) {  const response = await axios    .get('https://api.unsplash.com/search/photos', {      params: { query: term },      headers: {        Authorization: 'Client-ID
}
})console.log(response.data.results);}

Reference :

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
  3. Modern React with Redux by Stephen Grider

I am blogging what I’ve learned to find later here for myself. If you happened to read this shit and there is wrong information, it would be appreciated to add a comment below.

--

--