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.