Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

34
Vistas
Angular register es6 proxy as service

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
  }
});

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos