azure-functions-templates icon indicating copy to clipboard operation
azure-functions-templates copied to clipboard

Default template for new functions is misleading and not encouraging best practices

Open sinedied opened this issue 4 years ago • 4 comments

When a new function template is created (new project or just a new function), from CLI or VS Code extension, by default it's configured to respond to GET and POST requests, which is confusing for many newcomers and annoying for experienced users.

You rarely want to write such a function beyond an hello world example, as you usually prefer to have one function per verb (and it's also a best practice to my knowledge).

I've received confused feedbacks from new users that weren't sure whether they should implement all their CRUD logic within the same function because of that, as it being the default somehow implies this should be the way to go, which is wrong.

What about considering making the default function template use a single verb (GET) to avoid this confusion?

sinedied avatar Jul 26 '21 07:07 sinedied

Hi Sinedied,

I totally agree with you. The default template encourages bad practices as you may think the way to go for Microsoft when you write an API is to do something like this

if (req.Method == HttpMethod.Post) {
...
} else if (req.Method == HttpMethod.Get) {
...
}

Also, not sure if there is an official guideline for function naming (like tasks-get, task-post, task-get, etc) but if you want to use good practices with 1 function per HTTP verb, you usually end up adding a route in all your functions.json

tagazok avatar Jul 26 '21 08:07 tagazok

cc: @anthonychu , @fabiocav: Any thoughts on this?

soninaren avatar Aug 11 '21 20:08 soninaren

This is reasonable. @anthonychu any concerns? I'll have this added to the engineering backlog, but it would be good to get your input.

@AnatoliB FYI, if we do this, ideally, this would apply to all languages.

fabiocav avatar Sep 08 '21 20:09 fabiocav

+ @ggailey777 for impact on docs

anthonychu avatar Sep 13 '21 07:09 anthonychu