Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
环回连接器RESTAPI_Api_Loopbackjs - Fatal编程技术网

环回连接器RESTAPI

环回连接器RESTAPI,api,loopbackjs,Api,Loopbackjs,如何在环回上创建外部API 我想获取外部API数据并在环回应用程序上使用它,还想将我的环回输入传递到外部API并返回结果或响应。您需要https模块来调用环回内部的外部模块 假设您希望将外部API与任何模型脚本文件一起使用。型号名称应为Customer 在环回文件夹中。键入此命令并安装https模块 $npm install https --save 通用/models/customer.js 通用/models/customer.json 现在在/api/modelName/extenalA

如何在环回上创建外部API


我想获取外部API数据并在环回应用程序上使用它,还想将我的环回输入传递到外部API并返回结果或响应。

您需要
https
模块来调用环回内部的外部模块

假设您希望将外部API与任何模型脚本文件一起使用。型号名称应为
Customer

在环回文件夹中。键入此命令并安装
https
模块

$npm install https --save
通用/models/customer.js

通用/models/customer.json

现在在
/api/modelName/extenalApiProcessing

默认情况下,它是一种
post方法


更多信息

环回的概念是,包括。从文档中:

环回支持到后端系统的多个连接器 数据库

这些类型的连接器通常根据需要实现特定的方法 关于基础系统。例如,REST连接器代理 在推送连接器与iOS和API集成时调用REST API Android推送通知服务

如果您发布了有关要调用的API调用的详细信息,那么我可以为您添加一些更具体的代码示例。同时,这也来自文件:

datasources.json

MyModel": {
  "name": "MyModel",
  "connector": "rest",
  "debug": false,
  "options": {
    "headers": {
      "accept": "application/json",
      "content-type": "application/json"
    },
    "strictSSL": false
  },
  "operations": [
    {
      "template": {
        "method": "GET",
        "url": "http://maps.googleapis.com/maps/api/geocode/{format=json}",
        "query": {
          "address": "{street},{city},{zipcode}",
          "sensor": "{sensor=false}"
        },
        "options": {
          "strictSSL": true,
          "useQuerystring": true
        },
        "responsePath": "$.results[0].geometry.location"
      },
      "functions": {
        "geocode": ["street", "city", "zipcode"]
      }
    }
  ]
}
然后,您可以通过以下代码调用此api:


app.dataSources.MyModel.geocode('107 S B St','San Mateo','94401',processResponse)

@yongpin似乎你是StackOverflow的新手。欢迎来到StackOverflow。无论何时你得到了你想要的答案,然后点击绿色的勾号,使其成为正确的答案。这样其他人也会觉得它有用。嗨,罗宾,谢谢你的回答。我遵循了你的方法,但我仍然得到错误,除了这三个文件,我还需要做什么?这就是我得到的错误。fn.accepts.push({arg:p,type:args[p].type,^TypeError:无法读取未定义的Post me的属性'type',您已完成。错误和您的代码您到目前为止所尝试的内容Hi conradj,感谢您的回复。我收到了。非常感谢
 ....
 ....
 //Now add this line in the ACL property.
 "acls": [

    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "extenalApiProcessing"
    }
  ]
MyModel": {
  "name": "MyModel",
  "connector": "rest",
  "debug": false,
  "options": {
    "headers": {
      "accept": "application/json",
      "content-type": "application/json"
    },
    "strictSSL": false
  },
  "operations": [
    {
      "template": {
        "method": "GET",
        "url": "http://maps.googleapis.com/maps/api/geocode/{format=json}",
        "query": {
          "address": "{street},{city},{zipcode}",
          "sensor": "{sensor=false}"
        },
        "options": {
          "strictSSL": true,
          "useQuerystring": true
        },
        "responsePath": "$.results[0].geometry.location"
      },
      "functions": {
        "geocode": ["street", "city", "zipcode"]
      }
    }
  ]
}