我正在尝试代理服务器(http://www.swapi.co/api/starships用于实践,然后是Salesforce用于生产)。这将是一个反应本地应用程序的移动后端。我在这里跟踪文档:http://loopback.io/doc/en/lb2/REST-connector.html#resource-operations。然而,当使用生成器创建一个使用CRUD操作和星舰模型的“星舰”数据源时,当我试图使用内置的资源管理器来探索api时,什么都不会显示出来。当代理一个RESTful API时,我想使用RESTful API公开它,这在RESTful中还可用吗?
下面是用于查看api的资源管理器的屏幕截图:

以下是我正在采取的步骤:
$ slc loopback:datasource
? Enter the data-source name: starship
? Select the connector for starship: REST Services (supported by StrongLoop)
? Base URL for the REST service: http://www.swapi.co/api/starship
? Default options for the request: [left blank, hit enter]
? An array of operation templates: [left blank, hit enter]
? Use default CRUD mapping: (y/N) Y
$ slc loopback:model
? Enter model name: Starship
? Select data-source to attach Starship to: starship (rest)
? Select model's base class: Model
? Expose Person via the REST API? (Y/n) Y
? Custom plural form (used to build REST URL): starships
? Common model or server only? common
Let's add some Starship properties now.
Enter an empty property name when done.
? Property name: [left empty, hit enter]
$ npm start
> wfsapi@1.0.0 start /Users/me/projects/wfsapi
> node .
Web server listening at: http://0.0.0.0:3000
Browse your REST API at http://0.0.0.0:3000/explorer但是,当我导航到资源管理器时,只有用户api才会出现,而不是星舰。对我可能做错了什么有什么想法吗?下面是我可以找到的生成文件的内容:
通用/模型/星舰.
'use strict';
module.exports = function (Starship) {
};通用/型号/Starship.json
{
"name": "Starship",
"plural": "starships",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}服务器/数据源.server
{
"db": {
"name": "db",
"connector": "memory"
},
"starship": {
"name": "starship",
"baseURL": "http://www.swapi.co/api/starships",
"crud": true,
"connector": "rest"
}
}服务器/模型-config.json
{
...
"Starship": {
"datasource": "starship",
"public": true
}
}发布于 2016-10-24 22:23:05
问题是,您使用的是模型,而不是PersistedModel。
模型没有可访问的远程方法。
您需要将公共/模型/starship.json更改为
{
"name": "Starship",
"plural": "starships",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}有关更多信息,请查看http://apidocs.strongloop.com/loopback/#persistedmodel。
https://stackoverflow.com/questions/40194001
复制相似问题