使用rest api扩展重命名MarkLogic 7中的林
我可以在控制台中使用xquery重命名林使用rest api扩展重命名MarkLogic 7中的林,marklogic,Marklogic,我可以在控制台中使用xquery重命名林我将xquery转换为rest,并能够将其作为扩展安装,但当使用PUT请求调用它时,它无法工作 Curl将等待约30秒,然后什么也不做,并且不会进行更新。 我不知道这是为什么。非常感谢您的任何意见。 这是我的密码: $cat ernest.xqy xquery version "1.0-ml"; module namespace ernest = "http://marklogic.com/rest-api/resource/er
我将xquery转换为rest,并能够将其作为扩展安装,但当使用PUT请求调用它时,它无法工作
Curl将等待约30秒,然后什么也不做,并且不会进行更新。
我不知道这是为什么。非常感谢您的任何意见。 这是我的密码: $cat ernest.xqy
xquery version "1.0-ml";
module namespace ernest =
"http://marklogic.com/rest-api/resource/ernest";
import module namespace admin = "http://marklogic.com/xdmp/admin"
at "/MarkLogic/admin.xqy";
declare variable $oldname := "old-forestname";
declare variable $newname := "new-forestname";
declare function ernest:put(
$context as map:map,
$params as map:map,
$input as document-node()*
) as document-node()?
{
let $oldname := map:get($params, $oldname)
let $newname := map:get($params, $newname)
let $config := admin:get-configuration()
let $config := admin:forest-rename($config, admin:forest-get-id(admin:get-configuration(), $oldname), $newname )
return admin:save-configuration($config)
};
安装它的命令是:
curl --anyauth --user user:pass -X PUT -i -H "Content-type: application/xquery" -d@"./ernest.xqy" 'http://localhost:8040/v1/config/resources/ernest'
结果是:
HTTP/1.1 401 Unauthorized WWW-Authenticate: Digest realm="public", qop="auth", nonce="<some-hash>", opaque="<another-hash>" Content-type: text/html; charset=UTF-8 Server: MarkLogic Content-Length: 1942
Connection: Keep-Alive Keep-Alive: timeout=5 HTTP/1.1 204 Updated Server: MarkLogic Content-Length: 0 Connection: Keep-Alive Keep-Alive: timeout=5
我现在有点迷路了。在过去的几天里,我学到了很多东西,但我认为我在这里遇到了困难,所以任何建议都将不胜感激
谢谢你很好,你一直在进步 因为您正在执行PUT,所以curl可能希望您在命令行上提供有效负载。因为您将内容类型声明为application/xquery,所以它特别需要一个xquery负载,您不需要或不想将其发送到此服务 虽然它不完全符合REST原则,但您可以稍微欺骗一下,将资源服务更改为GET扩展。那么你就不必发送有效载荷了
希望这能有所帮助,第一步:验证扩展是否已正确部署:在浏览器中,转到。结果应至少包括名称、格式和支持的方法 假设一切顺利,我会检查扩展代码中是否有您的参数。添加一些
xdmp.log()。如果没有在代码中获取值
--编辑--
我想我明白了。关键是测试扩展时没有传入参数。我补充了这一点,然后发现curl希望在使用PUT时看到某种类型的体,但该体将是函数的$input,而不是$params$参数由URL参数填充。下面是对我有效的curl命令:
curl --anyauth --user admin:admin -X PUT -d 'undefined' \
'http://localhost:8000/v1/resources/ernest?rs:old-forestname=docs&rs:new-forestname=Documents'
请注意-d'undefined'
,以及
我用POSTman来解决这个问题——它是一个用于发送HTTP请求的Chrome扩展。我让它在那里工作,然后它给了我等效的curl命令 不值得单独回答的是我的“步骤1.1”。。在curl中使用-v选项。也许这会让我们了解情况……就是这样!!现在我会记住,当使用PUT时,我们总是必须传递一些参数。我猜在这种情况下:声明变量$oldname:=“oldfrestname”;只是为参数设置“名称”,而不是变量的实际值。:)非常感谢你!
curl --anyauth --user admin:admin -X PUT -d 'undefined' \
'http://localhost:8000/v1/resources/ernest?rs:old-forestname=docs&rs:new-forestname=Documents'