MarkLogic Customized REST API Creation without Gradle or Roxy Framework

MarkLogic Customized REST API Creation without Gradle or Roxy Framework

我想使用 MarkLogic 9.x.x 创建一个全新的 REST API,但不使用 Roxy 或 Gradle。我想指向一个文件,该文件包含基本 MarkLogic 设置中的自定义端点列表,然后将我的自定义逻辑保留在这些模块中。

我已经阅读了 REST API 文档以使用 CURL 创建一个文档,这样我们就可以使用 MarkLogic 提供的默认 APIs。

感谢任何详细的解释。

管理 REST api 真的是您最好的朋友,它就是为此目的而设计的。但是,创建进行适当 REST 调用的脚本可能很麻烦。 ml-gradle 可以在这方面为您提供支持。它可以为您生成一个包含所有 curl-statements 的 shell-script,您可以 运行 as-is,或者将其用作构建您自己的部署脚本集的起点。详情见:

https://github.com/marklogic-community/ml-gradle/wiki/Generating-a-shell-script

HTH!

迄今为止的两个回答都是正确和准确的并且有帮助,但是原始问题是 self-answered。

I've gone through the REST API documentation to create one by using CURL so that we can use default APIs provided by MarkLogic.

这实际上就是您所提问题的答案。

您是否考虑过使用 XQRS ?, you can create custom REST endpoints with ease using intuitive Function Annotations much like one would do with JAX-RS or Java Spring REST Services. It can be installed and used with or with-out Gradle.

您可以在这些 REST 函数中保留您的自定义逻辑,或者您可以在 JavaScript 代码中编写您的自定义逻辑,然后您从这些函数中 import/invoke。 XQRS 为您提供全面的灵活性。您可以使用直接位于 MarkLogic 上的 Human-Friendly URL 创建漂亮的 REST API,taking complete control of the URL Path. It's solid as a rock and unit tested to death. It scales with MarkLogic - i.e. you add more MarkLogic e-nodes and you automatically scale your REST servers, it's totally free and open source. The project is actively maintained and support is available on GitHub. If you've got a Swagger/OpenAPI interface file, you can generate a MarkLogic Stub 也可以为您节省很多时间。

函数根据您放置在函数上的注释简单地成为 可用 作为 REST 服务 - 您可以通过注释传递 ​​query/form 参数、cookie 和请求正文.查看此代码段以获取示例风味。

declare
  %rest:path("/factory/warehouse/wheel/{$wheel-id}")
  %rest:GET
function get-wheel($wheel-id as xs:string) {
  fn:doc($wheel-id)
};

declare
  %rest:path("/factory/warehouse/wheel/{$wheel-id}")
  %rest:PUT("{$doc}")
  %xdmp:update
function put-wheel($wheel-id as xs:string, $doc as document-node(element())) {
  xdmp:document-insert($wheel-id, $doc, map:entry("collections", "wheels"))
};

declare
  %rest:path("/factory/warehouse/wheel")
function list-wheels() {
  <wheels>{
    fn:collection("wheels")
  }</wheels>
};

要手动部署 ML rest API,请按照以下步骤操作

  • 创建模块数据库
  • 创建应用服务器 提供模块 DB、数据库、端口、URL 重写器
  • 的详细信息
  • 使用 qConsole 部署 xquery、xsl

    让 URI = 文件路径

    让路径 = xdmp:document-get($FilePath)

    xdmp:document-insert($URI,$path,(), ())

    其中 endpoints.xqy 将包含为您的其余部分定义的自定义端点 API 并且在内部您可以调用 search:search 函数以从 MarkLogic

    调用数据

    模块命名空间端点="urn:overstory:rest:modules:endpoints";

    声明命名空间 rest="http://marklogic.com/appservices/rest";

    (: -------------------------------------- -------------------------- :)

    将私有变量 $endpoints 声明为元素(rest:options) :=

         <request uri="^/getcontent$" endpoint="<xqy file" user-params="allow">
            <http method="GET"/>
        </request>
    

希望这会有所帮助