gpt4 book ai didi

api - 环回连接器 REST API

转载 作者:行者123 更新时间:2023-12-04 01:58:17 25 4
gpt4 key购买 nike

如何在 Loopback 上创建外部 API?

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

最佳答案

环回有non-database connectors的概念,包括 REST connector .来自文档:

LoopBack supports a number of connectors to backend systems beyond databases.

These types of connectors often implement specific methods depending on the underlying system. For example, the REST connector delegates calls to REST APIs while the Push connector integrates with iOS and Android push notification services.

如果您发布有关要调用的 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);

关于api - 环回连接器 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34131073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com