有人能解释一下如何使用APIC工具包创建API吗?
我想使用这个API来使用IBM Bluemix上的Cloudant DB或本地CouchDB来创建、读取和更新geoJSON数据。
下面是一个简单的典型数据示例,用于存储兴趣点的名称和坐标。
[{
"type": "Feature",
"properties": {
"name": "Nice Place 1"
},
"geometry": {
"type": "Point",
"coordinates": [16.45961, 48.23896]
}
}, {
"type": "Feature",
"properties": {
"name": "Nice Place 2"
},
"geometry": {
"type": "Point",
"coordinates": [16.34561, 49.89612]
}
}]发布于 2016-10-11 22:01:20
LoopBack支持GeoPoint (即GeoJSON中的点)数据类型。考虑到您的典型示例,假设您有一个名为: Feature的模型,那么要使用GeoPoint,您的Feature.json应该如下所示:
{
"name": "Feature",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string"
},
"geometry": {
"type": "geopoint"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}现在,这个以PersistedModel为基础的特性模型将具有作为REST端点公开的常见CRUD方法,并且您可以存储数据,例如,使用CURL:
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
\"name\": \"Nice Place 1\",
\"geometry\": {
\"lat\": 16.20,
\"lng\": 48.23
}
}" "http://0.0.0.0:3000/api/Features"希望这对创建支持GeoPoint的应用程序接口有所帮助。
Re: Cloudant db,我不确定它是否支持开箱即用的地理空间数据,但似乎支持它:https://cloudant.com/product/cloudant-features/geospatial/
发布于 2016-10-11 22:21:35
我用一个loopback应用程序尝试了上面的模型(使用cloudant作为ds),它是explorer:
使用示例数据创建:
{ "name": "string", "geometry": { "lat": 12, "lng": 13 } }
并从GET/ myGeoModels成功获取:
[ { "name": "string", "geometry": { "lat": 12, "lng": 13 }, "id": "f08301abe833ad427c9c61ffd30df8ef" } ]
APIC应该具有相同的环回行为。
https://stackoverflow.com/questions/39902689
复制相似问题