Skip to content

Instantly share code, notes, and snippets.

@cesar
Last active August 31, 2018 16:21
Show Gist options
  • Save cesar/7a70192095edd704ed7d5e38f516fb55 to your computer and use it in GitHub Desktop.
Save cesar/7a70192095edd704ed7d5e38f516fb55 to your computer and use it in GitHub Desktop.
function fakeFetchData(url, args) {
return new Promise((resolve, reject) => {
setTimeout(function() {
// here in the resolve, you can pass any object that you want
// to simulate the server response
return resolve({
posts: [
{
id: 1,
title: 'Somthing goes here',
contents: 'Lorem ipsum'
},
{
id: 2,
title: 'Some other contents',
contents: 'More lorem ipsum'
}
]
});
}, 500); // wait 0.5s
});
}
// This call simulates a server call, waits 0.5s and returns
// a successful payload
fakeFetchData('/posts').then(responseData => {
console.log(responseData);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment