I trying to find a way to create something like DRY http client service
, that will provide a boilerplate implementation for the backend calls based on a short API scheme description.
I would like to know is it possible to register es6 Proxy as angular service?
I need something like that:
import { Injectable } from "@angular/core";
const API = Object.freeze({
'user': {
endpoint: '/api/user/:id',
methods: ['GET', 'POST']
},
'users': {
endpoint: '/api/users',
methods: ['GET', 'POST']
}
});
// HOW TO: register something like this
@Injectable({ provideIn: 'root'})
const HttpClient = new Proxy(API, {
apply(target, thisArg, ...args) {
// Internal implementation
}
});