我试图使用他们提供的api-search访问存储在logz.io上的日志。
实际上,我可以使用curl命令成功访问,如我所示:
curl -X POST 'https://api.logz.io/v1/search'
--header "X-API-TOKEN: API-TOKEN-GENERATED"
--header "Content-Type: application/json"
-d '{"query": {"term": {"_id": {"value": "Log Id Here"}}}}', 就像https://github.com/logzio/public-api/tree/master/search说的。
但是,当我使用AWS AppSync api,使用带有params名称的HttpResolver数据源:HttpDataSourceTest,类型:HTTP和终结点:https://api.logz.io/v1/search时,我定义了HttpResolver,即请求和响应模板解析器:
schema.grapgql
type Query {
GetLog(id: String): Log
} 请求模板解析器:
{
"version": "2018-05-29",
"method": "POST",
"params": {
"headers": {
"Content-Type: application/json",
"X-API-TOKEN":"API-TOKEN-GENERATED"
},
"body":{
"query": {
"term": {
"_id": {
"value": "$context.arguments.id"
}
}
}
}
},
"resourcePath": "/"
} 响应模板解析器:
$utils.toJson({"TimeStamp":"$ctx.result.statusCode $ctx.result.body" })经过几次调度和失败后,我保持了非常简单的状态,只需在查询和显示状态上请求TimeStamp字段,然后返回所有响应。
在所有这些配置之后,我得到了以下响应:
{
"data": {
"GetLog": {
"TimeStamp": "403 {\"message\":\"Forbidden\"}"
}
}
}同样的结果,当我跳过头时,就像HttpDatasource不发送那个params一样。我是新使用所有这些技术,AWS服务和Logz.io,请告诉我,如果我遗漏了什么地方。
发布于 2018-08-31 17:00:17
一个单独的http数据源可以使用我的许多解析器,并相对于同一个根访问不同的路径。因此,当您设置HTTP数据源时,将端点设置为https://api.logz.io,然后将其用于请求映射模板:
{
"version": "2018-05-29",
"method": "POST",
## E.G. if full path is https://api.xxxxxxxxx.com/posts then resourcePath would be /posts **
"resourcePath": "/v1/search",
"params":{
"body":{
"query": {
"term": {
"_id": {
"value": "$context.arguments.id"
}
}
}
},
"headers":{
"Content-Type": "application/json",
"X-API-TOKEN":"API-TOKEN-GENERATED"
}
}
}https://stackoverflow.com/questions/52119486
复制相似问题