Skip to content

Instantly share code, notes, and snippets.

View karlguillotte's full-sized avatar

Karl Guillotte karlguillotte

  • Montréal, Canada
  • 14:37 (UTC -04:00)
View GitHub Profile
@karlguillotte
karlguillotte / javascript-proxy-as-rest-client.js
Created February 8, 2022 16:34 — 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
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
return async function(id = "") {
const response = await fetch(`${url}/${key}/${id}`)
if (response.ok) {
return response.json();
@karlguillotte
karlguillotte / cache.js
Created August 27, 2021 20:59 — forked from lesleh/cache.js
Basic memory cache implementation for JavaScript.
function Cache(config) {
config = config || {};
config.trim = config.trim || 600;
config.ttl = config.ttl || 3600;
var data = {};
var self = this;
var now = function() {
return new Date().getTime() / 1000;