Skip to content

Instantly share code, notes, and snippets.

View miguelrk's full-sized avatar

miguelrk

View GitHub Profile
@miguelrk
miguelrk / kv-proxy.js
Last active September 29, 2022 16:56 — forked from stelf/proxyftw.js
using ES6 proxies and async/await to dynamically, yet almost transparently connect to some remote data provider
const providerHandler = {
get: async(target, name) => {
console.log('load someting from remote...')
return new Promise( (res, rej) => {
setTimeout(() => res(42), 4200)
})
},
set: function (obj, prop, value) {
return new Promise((res, rej) => {
console.log('save someting remotely...')
@miguelrk
miguelrk / github-proxy-client.js
Created March 11, 2022 15:53 — forked from DavidWells/github-proxy-client.js
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
async function getRepo() {
@miguelrk
miguelrk / javascript-proxy-as-rest-client.js
Created March 11, 2022 15:52 — forked from DavidWells/javascript-proxy-as-rest-client.js
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {