Skip to content

Instantly share code, notes, and snippets.

@carlrip
Created January 27, 2019 10:35
Show Gist options
  • Save carlrip/91f0e6b5d9bd54bf08e0e4827f3b036a to your computer and use it in GitHub Desktop.
Save carlrip/91f0e6b5d9bd54bf08e0e4827f3b036a to your computer and use it in GitHub Desktop.
async fetch
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