Created
January 27, 2019 10:35
-
-
Save carlrip/91f0e6b5d9bd54bf08e0e4827f3b036a to your computer and use it in GitHub Desktop.
async fetch
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
export const http = async (request: RequestInfo): Promise<any> => { | |
return new Promise(resolve => { | |
fetch(request) | |
.then(response => response.json()) | |
.then(body => { | |
resolve(body); | |
}); | |
}); | |
}; | |
// example consuming code | |
const data = await http("https://jsonplaceholder.typicode.com/todos"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment