hey, some insights please. So my frontend makes PUT requests to my backend,
and my backend does the stuff (request to another API)
I have like 10 put requests this way,
router.put('/currencies/:uuid/access', access)
router.put('/currencies/:uuid/staff', staff)
router.put('/currencies/:uuid/name', name)
see the pattern? , the last resource is different. Now inside the function, the code is lik this
fetch('API_URL/access', {body:{access: req.body.data}})
fetch('API_URL/staff', {body:{staffId:req.body.data}})
and the parsing etc, hence its all same. Should i keep it this way , as in writing a separate function and repeate the code in all function (ofc i have made the util of fetch, but still its a bit of code i have to repeate/copy/paste everytime i make new endpoint)
what i am thinking is,
router.put('/currencies/:uuid/:method', general)
inside generale function
const config = { "access": {path: "access", bodyVariable: "access"}, "staff":{path: "staff", bodyVariable: "staffId"} }
const correct = config[req.params.method]
fetch(`API_URL/${correct.path}`, {body: { [correct.bodyVariable]: req.body.data}
simple one function for all of them? i have heard a fellow dev saying this would be bad practice, if i ever need to change some endpoint data, i'll have to separate function from this.