用FlutterFire cloud_functions,所有的请求都是POST吗?
With FlutterFire cloud_functions, are all requests POST?
我正在为 Flutter Web 应用程序使用 Firebase Functions 编写 API。我看不出有任何方法可以使用 FlutterFire cloud_functions.dart 包来使用除 'POST.' 之外的任何 http 方法调用我的函数我是不是遗漏了什么?
使用这个 Firebase 函数:
export const hello = functions.https.onRequest(async (req, res) => {
cors(req, res);
functions.logger.info(req.method);
switch (req.method.toLowerCase()) {
case 'get':
res.status(200).send({'data': 'get', 'error': false });
break;
case 'post':
res.status(201).send();
break;
case 'options':
res.status(200).send();
break;
default:
res.status(405).send({error: true, data: {}, message: 'method not allowed'});
}
});
有没有办法让代码像
HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('hello');
HttpsCallableResult result = await callable();
print(result.data);
发出 GET 请求?
使用 Firebase Functions SDK 对可调用函数发出的请求始终是 POST,并且无法更改。如果您仔细阅读 protocol specification for callable functions.
,您可以确切地看到它在做什么
如果您想使用 Firebase Functions SDK 来调用一个函数,您还必须使用 onCall
而不是 onRequest
来定义您的函数,如 documentation for callable functions 中所述。
如果您使用 onRequest
定义您的函数,那么您应该使用标准的 HTTP 客户端库来调用它。 Functions 客户端 SDK 将无法运行。
您不能真正混合和匹配 onRequest
和 onCall
函数 - 它们有不同的用例和实现细节。
我正在为 Flutter Web 应用程序使用 Firebase Functions 编写 API。我看不出有任何方法可以使用 FlutterFire cloud_functions.dart 包来使用除 'POST.' 之外的任何 http 方法调用我的函数我是不是遗漏了什么?
使用这个 Firebase 函数:
export const hello = functions.https.onRequest(async (req, res) => {
cors(req, res);
functions.logger.info(req.method);
switch (req.method.toLowerCase()) {
case 'get':
res.status(200).send({'data': 'get', 'error': false });
break;
case 'post':
res.status(201).send();
break;
case 'options':
res.status(200).send();
break;
default:
res.status(405).send({error: true, data: {}, message: 'method not allowed'});
}
});
有没有办法让代码像
HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('hello');
HttpsCallableResult result = await callable();
print(result.data);
发出 GET 请求?
使用 Firebase Functions SDK 对可调用函数发出的请求始终是 POST,并且无法更改。如果您仔细阅读 protocol specification for callable functions.
,您可以确切地看到它在做什么如果您想使用 Firebase Functions SDK 来调用一个函数,您还必须使用 onCall
而不是 onRequest
来定义您的函数,如 documentation for callable functions 中所述。
如果您使用 onRequest
定义您的函数,那么您应该使用标准的 HTTP 客户端库来调用它。 Functions 客户端 SDK 将无法运行。
您不能真正混合和匹配 onRequest
和 onCall
函数 - 它们有不同的用例和实现细节。