lundi 23 août 2021

Multi actions API best Practice / Design Pattern

I have an API with a multi actions POST function.

It is structured like that :

exports.myFunction = functions.https.onRequest((request: any, response: any) => {
    const action: 'a' | 'b' | 'c' = request.body.action;
    switch(action) {
      case 'a':
        doProcessA();
        break;
      case 'b': 
        doProcessB();
        break;
      case 'c': 
        doProcessC();        
        break;
    }
    response.send('done');
});

I cannot split this function into 3 exposed functions. Regarding this contraint, is my code clean, or is there any better practice / Design pattern to handle such situation ?

Aucun commentaire:

Enregistrer un commentaire