我在环回 4 数据源文件中声明 POST 操作时遇到问题。
我的模板如下:
{
"template": {
"method": "POST",
"url": "https://reqres.in/api/login"
},
"functions": {
"login": []
}
}
我的服务接口
login(email: string, password: string): Promise<any>;
我的控制器
@post('/loginTest')
async testingLogin(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TestModel, {
title: 'Post',
}),
},
},
})
testModel: TestModel, )
: Promise<any> {
// TEST MODEL CONTAIN JSON OBJECT {email: "" , password: ""}
console.log("Test Model Representation: ", testModel)
try {
var response = await this.loginService.login(testModel.email, testModel.password);
} catch (error) {
console.log("error", error)
}
console.log("Fake POST response", response)
return response;
};
我正在使用这个假的API:https://reqres.in/api/login 我收到以下错误:
Test Model Representation: { email: 'string', password: 'string' }
error Error: {"error":"Missing email or username"}
at callback (D:loginAppnode_modulesloopback-connector-restlibrest-builder.js:541:21)
at D:loginAppnode_modulesloopback-datasource-jugglerlibobserver.js:269:22
at doNotify (D:loginAppnode_modulesloopback-datasource-jugglerlibobserver.js:157:49)
at RestConnector.ObserverMixin._notifyBaseObservers (D:loginAppnode_modulesloopback-datasource-jugglerlibobserver.js:180:5) {
statusCode: 400,
message: '{"error":"Missing email or username"}'
}
Fake POST response undefined
看起来我的电子邮件和密码没有传递?感谢您的任何帮助。
在数据源文件中定义的login
函数应与服务接口匹配。这意味着它将是这样的:
"functions": {
"login": ["email", "password"]
}