4 ms·
I built a Proxy-based microlib for making fluent REST calls just on a lark a couple years ago. It was never anything production-ready, but it was so handy that
by sli 2y ago
I built a Proxy-based microlib for making fluent REST calls just on a lark a couple years ago. It was never anything production-ready, but it was so handy that I used it in all of my JS projects until I moved away from webdev. The API was basically:
const api = new Proxy({route: baseRoute}, handler); // handler is the microlib's export
const result = await api.get.some.route.invoke(); // GET {baseRoute}/some/route
invoke() is just how it finally fires the call. I didn't feel like spending too much time making it automatic, the benefits just weren't large enough to justify compared to just calling invoke().
- dimava 2y agoElysia Eden [1] uses the same thing, except putting `get` to the place of `invoke` `api.some.route.get()` [1] https://elysiajs.com/eden/treaty/overview.html https://elysiajs.com/eden/treaty/overview.html