Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!