
coco/public-things-api提供存储在Neo4j图数据库中的事物(Things)的公共API。目前事物正迁移至新的Public Concepts API,因此本API最终将被弃用。自2018年7月起,对本服务的请求将通过概念API重定向,然后转换以匹配现有契约并返回。
showRelationship查询参数获取事物间的关系(包括broader、broaderTransitive、narrower、related类型)适用于需要读取Neo4j图数据库中存储的事物信息的应用,可获取事物的基本信息及其与其他概念的关系。注意:本API正处于迁移阶段,未来将被Public Concepts API替代,建议新应用直接使用Public Concepts API。
| 参数名 | 描述 | 默认值 | 环境变量对应 |
|---|---|---|---|
| --app-system-code | 应用的系统代码 | public-things-api | APP_SYSTEM_CODE |
| --port | 监听端口 | 8080 | APP_PORT |
| --env | 应用运行环境(local/生产等) | local | - |
| --cache-duration | GET请求的缓存时长(例如2h45m表示7440秒) | 30s | CACHE_DURATION |
| --logLevel | 日志级别(debug/info/warn/error) | info | LOG_LEVEL |
| --publicConceptsApiURL | Public Concepts API端点URL | http://localhost:8080 | CONCEPTS_API |
bashdocker run -d -p 8080:8080 \ -e APP_SYSTEM_CODE=public-things-api \ -e APP_PORT=8080 \ -e CACHE_DURATION=30s \ -e LOG_LEVEL=info \ -e CONCEPTS_API=[***] \ coco/public-things-api
bashdocker run -d -p 8081:8081 \ -e APP_SYSTEM_CODE=my-things-api \ -e APP_PORT=8081 \ -e CACHE_DURATION=5m \ -e LOG_LEVEL=debug \ -e CONCEPTS_API=[***] \ coco/public-things-api --env=production
通过UUID获取事物的基本信息:
bashcurl http://localhost:8080/things/{concept-uuid} | jq
响应示例:
json{ "id": "[***]", "apiUrl": "[***]", "prefLabel": "Solar Wars", "types": [ "[***]", "[***]", "[***]" ], "directType": "[***]", "aliases": [ "Solar Wars" ] }
通过showRelationship参数获取事物与其他概念的关系,支持的值:broader( broader关系)、broaderTransitive(broader传递关系)、narrower(narrower关系)、related(related关系)。
bashcurl "http://localhost:8080/things/{concept-uuid}?showRelationship=broaderTransitive&showRelationship=related&showRelationship=narrower" | jq
响应示例(包含关系):
json{ "id": "[***]", "apiUrl": "[***]", "prefLabel": "Solar Wars", "types": [ "[***]", "[***]", "[***]" ], "directType": "[***]", "aliases": [ "Solar Wars" ], "narrowerConcepts": [ { "id": "[***]", "apiUrl": "[***]", "prefLabel": "Macroeconomics", "types": [ "[***]", "[***]", "[***]" ], "directType": "[***]", "predicate": "[***]" } ], "broaderConcepts": [ { "id": "[***]", "apiUrl": "[***]", "prefLabel": "Trade disputes", "types": [ "[***]", "[***]", "[***]" ], "directType": "[***]", "predicate": "[***]" } ], "relatedConcepts": [ { "id": "[***]", "apiUrl": "[***]", "prefLabel": "Renewable Energy", "types": [ "[***]", "[***]", "[***]" ], "directType": "[***]", "predicate": "[***]" } ] }
通过多个uuid参数批量获取事物描述,支持自动解析非规范UUID:
bashcurl "http://localhost:8080/things?uuid={canonical-uuid}&uuid={non-canonical-uuid}&uuid={another-uuid}" | jq
响应示例:
json{ "things": { "a11fa00f-777d-484a-9ebc-fbf81b774fc0": { "id": "[***]", "apiUrl": "[***]", "prefLabel": "Solar Wars", "types": [ "[***]", "[***]", "[***]" ], "directType": "[***]", "aliases": [ "Solar Wars" ] }, "non-canonical-uuid": { "id": "[***]", "apiUrl": "[***]", "prefLabel": "Resolved Thing", "types": [ "[***]", "[***]" ], "directType": "[***]", "aliases": [] } } }
/__gtg: 健康状态检查(返回200表示正常)/__health: 详细健康信息/__build-info: 应用构建信息/__ping: 心跳检查(返回"pong")main.go中初始化local环境:日志输出到控制台/__build-info和/__ping端点的请求不记录日志如需从源码构建,执行以下步骤:
bashcurl [***] | sh
bashmkdir $GOPATH/src/github.com/Financial-Times/public-things-api cd $GOPATH/src/github.com/Financial-Times git clone [***] cd public-things-api && dep ensure -vendor-only
bashgo build .
bashgo test ./... go install
--help查看参数):bash$GOPATH/bin/public-things-api --help
参数说明:
Options: --app-system-code 应用的系统代码(环境变量 $APP_SYSTEM_CODE)(默认 "public-things-api") --port 监听端口(环境变量 $APP_PORT)(默认 "8080") --env 应用运行环境(默认 "local") --cache-duration GET请求缓存时长(例如2h45m)(环境变量 $CACHE_DURATION)(默认 "30s") --logLevel 日志级别(环境变量 $LOG_LEVEL)(默认 "info") --publicConceptsApiURL Public Concepts API端点URL(环境变量 $CONCEPTS_API)(默认 "http://localhost:8080")
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务