Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
Best (and scaleable) way to select from multiple services in javascript

Im in the process of building a system that can communicate with 1 or multiple CMS's within the project. Each of these services have a slightly different structure in the request but are looking to return the data in a json that follows a fixed format for the application.

My current approach is to have something similar to below.

///apiRequestA.js
function TestA()
{
    console.log("Service A")
}

export {TestA}
///apiRequestB.js
function TestB()
{
    console.log("Service B")
}

export {TestB}
///masterService.js

import {TestA} from "@/service/apiRequestA";
import {TestB} from "@/service/apiRequestB";
const Service = "A"
function Test()
{
   if(Service === "A")
   {
     return TestA()
   }
   else if(Service === "B")
   {
     return TestB
   }
   /// etc
}

This would work, but feels like for a rather large collection of requests / if was to expand to a 3 or more end points (could be likely), then the masterService can become very long and messy.

From C# background i would have all the base functions called the same and then use a preprocesser to determine which service to import into master and then just have the master service call the function.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda