Reputation: 2161
I am developing an API using Azure Functions. Should I have a small number of functions and call many diffrent actions E.G my Url parameters might contain
?action=method1
or
?action=method2
and then perhaps use a switch statement like this:
var action = query["action"].ToString();
switch (action)
{
case "method1":
return await method1();
case "method2":
return await method2();
....
This way I only really need one function to accomplish many actions. Is this a wise way forward? Should I intead have one function for each method? I am confused.
Upvotes: 2
Views: 758
Reputation: 14324
Mostly It depends on the logic you want, if you use the switch you could use only one function URL to do the request(only need pass the query parameter).
If you use multiple functions, the URL will be chang(firstly the function name, then is the authorization key).
And if all methods are totally different, if you split them to multiple functions, this could reduce some running time like judgment even it won't take much time.
Hope this could help you if you still have other problems please provide more details.
Upvotes: 2