向Google Cloud函数添加自定义参数/查询/标题
我基本上想知道是否可以根据我作为参数传递给它的https Google Cloud函数的执行方式不同(就像任何带有参数的普通函数一样)。可能通过URL内的简单查询或任何其他可行的方法。
作为示例,请看任何教程中的基本启动器功能:
exports.helloWorld = functions.https.onRequest((req, res) => {
res.status(200).send('Hello, World!');
});
我想做类似的事情:
exports.helloWorld = functions.https.onRequest((req, res) => {
let name = req.query;
res.status(200).send(`Hello, {name}!`);
});
我希望这是有道理的。任何帮助,将不胜感激。
回答如下:您好,因为HTTPS Cloud Functions是POST请求,所以您可以在请求正文中传递任何类型的参数。
示例:云功能:
exports.helloWorld = functions.https.onRequest((req, res) => {
let name = req.body.name;
res.status(200).send(`Hello, {name}!`);
});
客户:
fetch('https://firebase.url/helloWorld ', {
method: 'post',
body: {name: "Name"},
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data)
});
您可以在这里使用任何请求方法。
希望这会有所帮助。
向Google Cloud函数添加自定义参数/查询/标题
我基本上想知道是否可以根据我作为参数传递给它的https Google Cloud函数的执行方式不同(就像任何带有参数的普通函数一样)。可能通过URL内的简单查询或任何其他可行的方法。
作为示例,请看任何教程中的基本启动器功能:
exports.helloWorld = functions.https.onRequest((req, res) => {
res.status(200).send('Hello, World!');
});
我想做类似的事情:
exports.helloWorld = functions.https.onRequest((req, res) => {
let name = req.query;
res.status(200).send(`Hello, {name}!`);
});
我希望这是有道理的。任何帮助,将不胜感激。
回答如下:您好,因为HTTPS Cloud Functions是POST请求,所以您可以在请求正文中传递任何类型的参数。
示例:云功能:
exports.helloWorld = functions.https.onRequest((req, res) => {
let name = req.body.name;
res.status(200).send(`Hello, {name}!`);
});
客户:
fetch('https://firebase.url/helloWorld ', {
method: 'post',
body: {name: "Name"},
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data)
});
您可以在这里使用任何请求方法。
希望这会有所帮助。