Last active
August 31, 2018 16:21
-
-
Save cesar/7a70192095edd704ed7d5e38f516fb55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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