Loading TOC...

PUT /v1/config/resources/{name}

Summary

Create or update a resource service extension.

URL Parameters
provider? The name of the provider of the service. Optional, used only as metadata.
version? The version of the service. Optional, used only as metadata.
title? The title of the service. Optional, used only as metadata.
description? A description of the service. Optional, used only as metadata.
method* The name of an HTTP method supported by the extension. Accepted values: get, put, post delete. The parameter may be specified multiple times to specify multiple methods. Optional, used only as metadata.
method:{name}* The name, type, and cardinality of a method parameter. For example, get:the-uri=string. The method must be one of get, put, post, or delete. The {name} is the parameter name. The parameter value is an XQuery SequenceType, including cardinality (*, ?, etc.) such as appears in the type declaration of an XQuery function parameter. Optional, used only as metadata.
Request Headers
Content-type The type of the request body. Since request body must contain XQuery or JavaScript that implements the services provided for the named resource, the content type must be application/xquery or application/vnd.marklogic-javascript.

Required Privileges

This operation requires the rest-admin role, or the following privileges:

http://marklogic.com/xdmp/privileges/rest-admin

http://marklogic.com/xdmp/privileges/rest-writer

http://marklogic.com/xdmp/privileges/rest-reader

Usage Notes

For details on implementing a resource service extension, see Extending the REST API in the REST Application Developer's Guide.

Example

# Note: Use --data-binary instead of -d with curl to preserve newlines
# in the input, such as line-oriented comments (//).

$ curl --anyauth --user user:password -X PUT -i \
  -H "Content-type: application/vnd.marklogic-javascript" \
  --data-binary @"./example.sjs" \
  'http://localhost:8004/v1/config/resources/example'

==> A JavaScript resource addressable through /v1/resources/example. 
    MarkLogic Server returns the following headers:

Server: MarkLogic
Content-Type: text/xml; charset=UTF-8
Content-Length: 211
Connection: close

HTTP/1.1 204 Created
Server: MarkLogic
Content-Type: text/plain; charset=UTF-8
Content-Length: 4
Connection: close
  

Example

$ curl --anyauth --user user:password -X PUT -i \
  -H "Content-type: application/xquery" -d@"./example.xqy" \
  'http://localhost:8004/v1/config/resources/example'

==> An XQuery resource addressable through /v1/resources/example. 
    MarkLogic Server returns the following headers:

Server: MarkLogic
Content-Type: text/xml; charset=UTF-8
Content-Length: 211
Connection: close

HTTP/1.1 204 Created
Server: MarkLogic
Content-Type: text/plain; charset=UTF-8
Content-Length: 4
Connection: close
  

Example

$ curl --anyauth --user user:password -X PUT -i \
  -H "Content-type: application/xquery" -d@"./example.xqy" \
  'http://localhost:8004/v1/config/resources/example?method=get&get:the-uri=string&provider=Acme Widgets'

==> An XQuery resource addressable through /v1/resources/example. The metadata
    for the extension will include parameter name and type information for 
    the GET method. MarkLogic Server returns the following headers:

Server: MarkLogic
Content-Type: text/xml; charset=UTF-8
Content-Length: 211
Connection: close

HTTP/1.1 204 Created
Server: MarkLogic
Content-Type: text/plain; charset=UTF-8
Content-Length: 4
Connection: close
  

Comments

  • This command: curl --anyauth --user user:pass -X PUT -i -H "Content-type: application/xquery" -d@"./extensionBla.xqy" 'http://localhost:8040/v1/config/resources/extensionBla' returns html code with: Error code: 500 Reason: Invalid content: and log says: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid extensionBla extension: could not parse XQuery extension extensionBla; please see the server error log for detail XDMP-IMPMODNS: (err:XQST0059) Import module namespace http://marklogic.com/rest-api/resource/extensionBla does not match target namespace http://marklogic.com/rest-api/resources/extensionBla of imported module /marklogic.rest.resource/extensionBla/assets/resource.xqy; extensionBla either is not a valid module or does not provide extension functions (delete, get, put, post) in the http://marklogic.com/rest-api/resource/extensionBla namespace the code is: xquery version "1.0-ml"; (:module namespace yourNSPrefix = "http://marklogic.com/rest-api/resource/extensionBla"; :) module namespace yourNSPrefix = "http://marklogic.com/rest-api/resources/extensionBla"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; (: declare function yourNSPrefix:get( $context as map:map, $params as map:map ) as document-node()* :) (:declare function yourNSPrefix:resource( :) declare function yourNSPrefix:put( $context as map:map, $params as map:map (:$input as document-node()* :) (: ) as document-node()? :) ) as document-node() { let $old-name := map:get($params, "forest-1") let $new-name := map:get($params, "forest-ernest") let $config := admin:get-configuration() let $config := admin:forest-rename($config, admin:forest-get-id($old-name), $new-name) return admin:save-configuration($config) }; (: declare function yourNSPrefix:post( $context as map:map, $params as map:map, $input as document-node()* ) as document-node()* declare function yourNSPrefix:delete( $context as map:map, $params as map:map ) as document-node()? :) I've been trying to figure it out for a few days now but I'm out of ideas. What am I doing wrong here? This is in ML 7. Thank you
Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy