Created
June 14, 2017 11:37
-
-
Save alonronin/00e052a851d5173fd3ca922cb984e6ac to your computer and use it in GitHub Desktop.
An api implementation using Proxy
This file contains hidden or 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
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