Skip to content

Instantly share code, notes, and snippets.

@alonronin
Created June 14, 2017 11:37
Show Gist options
  • Save alonronin/00e052a851d5173fd3ca922cb984e6ac to your computer and use it in GitHub Desktop.
Save alonronin/00e052a851d5173fd3ca922cb984e6ac to your computer and use it in GitHub Desktop.
An api implementation using Proxy
const target = {};
const handler = {
get(target, property, receiver) {
return fetch(`https://jsonplaceholder.typicode.com/${property}`)
.then(r => r.json())
}
};
const api = new Proxy(target, handler);
api.posts.then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment