Search code examples
marklogicmarklogic-8

Marklogic Rest Resource extension not honoring metadata.xml


I have a rest resource extension where I specify the parameter types.. But what I noticed is that params that I get in my POST or GET is of not the same type as the parameter type in my metadata.xml.. They are all xs:string. But when I look at the out-of-box search API, it does honor the parameter types.. I was digging a little deeper and I noticed that in /MarkLogic/rest-api/endpoints/config.xqy the get-rsrc-list-query-rule() does not get my metadata rules that I specified in metadata.xml, but for out-of-box search rest api, it does get the right rules..

declare function conf:get-rsrc-list-query-rule() as element(rest:request) {
    <rest:request
            allow-post-alias="true"
            fast-match="/*/config/resources"
            uri="^/(v1|get-rsrc-list-query-ruleLATEST)/config/resources/?$"
            endpoint="/MarkLogic/rest-api/endpoints/resource-list-query.xqy">
        <rest:http method="GET">
            <rest:param name="format"  required="false" values="json|xml"/>
            <rest:param name="refresh" required="false" as="boolean"/>
        </rest:http>
    </rest:request>
};

whereas for out-of the box search rest api, the right rules are sent

declare function conf:get-search-query-request-rule() as element(rest:request) {
    <rest:request
            allow-post-alias="true"
            fast-match="/*/search"
            uri="^/(v1|LATEST)/search(/)?$"
            endpoint="/MarkLogic/rest-api/endpoints/search-list-query.xqy"
            user-params="allow-dups">
        <rest:http method="GET">
            <rest:param  name="q" required="false"/>
            <rest:param name="format" required="false" values="json|xml"/>
            <rest:param  name="start"  as="unsignedLong" required="false"/>
            <rest:param  name="pageLength" as="unsignedLong"  required="false"/>
            <rest:param name="category" required="false" repeatable="true"
                values="content|metadata|{string-join(docmodcom:list-metadata-categories(),"|")}"/>
            <rest:param  name="options" as="string"  required="false"/>
            <rest:param  name="collection" as="string"  required="false" repeatable="true"/>
            <rest:param  name="directory" as="string"  required="false" repeatable="false"/>
            <rest:param  name="view" as="string" values="metadata|results|facets|all|none"/>
            <rest:param  name="txid" as="string" required="false"/>
            <rest:param name="database"     required="false"/>
            <rest:param  name="transform" required="false"/>
            <rest:param  name="structuredQuery" required="false"/>
            <rest:auth>
              <rest:privilege>http://marklogic.com/xdmp/privileges/rest-reader</rest:privilege>
              <rest:kind>execute</rest:kind>
            </rest:auth>
        </rest:http>
        <rest:http method="POST">
            <rest:param  name="q" required="false"/>
            <rest:param name="format" required="false" values="json|xml"/>
            <rest:param name="category" required="false" repeatable="true"
                values="content|metadata|{string-join(docmodcom:list-metadata-categories(),"|")}"/>
            <rest:param  name="start"  as="unsignedLong" required="false"/>
            <rest:param  name="pageLength" as="unsignedLong"  required="false"/>
            <rest:param  name="options" as="string"  required="false"/>
            <rest:param  name="collection" as="string"  required="false" repeatable="true"/>
            <rest:param  name="directory" as="string"  required="false" repeatable="false"/>
            <rest:param  name="view" as="string" values="metadata|results|facets|all|none"/>
            <rest:param  name="txid" as="string" required="false"/>
            <rest:param name="database"     required="false"/>
            <rest:param  name="transform" required="false"/>
            <rest:content-type>text/xml</rest:content-type>
            <rest:content-type>text/json</rest:content-type>
            <rest:content-type>application/xml</rest:content-type>
            <rest:content-type>application/json</rest:content-type>
            <rest:auth>
              <rest:privilege>http://marklogic.com/xdmp/privileges/rest-reader</rest:privilege>
              <rest:kind>execute</rest:kind>
            </rest:auth>
        </rest:http>
        <rest:http method="HEAD"/>
        <rest:http method="OPTIONS"/>
    </rest:request>
};

I thought when I specified my parameter types, the resource rest api will enforce the types, else will raise an error, but that is not the case.. It does with the out-of-box rest api.

Am I not understanding this right ? Did I get all this wrong ? How do I tell the rest resource extension to honor my parameter types specified in my metadata.xml


Solution

  • The metadata is optional information about a resource service extension that you can get to find out what extensions are available.

    The documentation puts it this way:

    "If the extension service expects parameters, you can optionally 'declare' the parameters using request parameters when installing the extension. This information is metadata that can be returned by a GET request to /config/resources. It is not used to check parameters on requests to the extension."

    http://docs.marklogic.com/guide/rest-dev/extensions#id_59112

    "MarkLogic Server returns a summary of the installed extensions in XML or JSON.... The amount of information available about a given extension depends on the amount of metadata provided during installation of the extension."

    http://docs.marklogic.com/guide/rest-dev/extensions#id_73853

    You can cast the string to any type in your extension, for instance by calling xs:int() or xs:double().

    Hoping that helps,