Skip to content

Instantly share code, notes, and snippets.

@johnpapa
Last active May 1, 2021 08:37
Show Gist options
  • Select an option

  • Save johnpapa/1c2fd722e23c640de5eeb8ab3fa3e44a to your computer and use it in GitHub Desktop.

Select an option

Save johnpapa/1c2fd722e23c640de5eeb8ab3fa3e44a to your computer and use it in GitHub Desktop.
Our idea for simpler template code
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
const name = (req.query.name || (req.body && req.body.name));
const responseMessage = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
}
module.exports = async function (context, req) {
context.log('HTTP trigger function processed a request.');
const name = req.query.name || (req.body && req.body.name);
let message;
if (name) {
message = `Hello ${name}`;
} else {
message = `Pass a name in the query string or body to say hello.`;
}
context.res = {
body: message,
};
};
@johnpapa
Copy link
Copy Markdown
Author

johnpapa commented Mar 30, 2021

For readability we are Intentionally avoiding optional chaining, ternary, and object value property shorthand

@craigshoemaker
Copy link
Copy Markdown

We also updated the text to be more conversational.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment