MarkLogic Server 11.0 Product Documentation
xdmp:http-put

xdmp:http-put(
   $uri as xs:string,
   [$options as (element()|map:map)?],
   [$data as node()?]
) as item()+

Summary

Sends an HTTP PUT request to an HTTP server. The HTTP server should return a response, which will differ depending on the action the HTTP server takes for the PUT.

Parameters
uri The URI to which the data is to be put.
options Options with which to customize this operation. You can specify options as either an XML element in the "xdmp:http" namespace, or as a map:map. The options names below are XML element localnames. When using a map, replace the hyphens with camel casing. For example, "an-option" becomes "anOption" when used as a map:map key. This function supports the following options, plus the options from the xdmp:http-get function.

data

This option can contain any string. Anything in the data option is sent as a string in the PUT body. To put binary data in the request body, use the optional third parameter instead.

The other options are the same as the other xdmp:http-* functions, and the options are documented with the xdmp:http-get $options parameter.

data Data to put in the request body. This is an alternative to the data option for the second parameter that allows binary content to be specified for the body of the PUT.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-http-put

Usage Notes

The http functions only operate on URIs that use the http or https schemes; specifying a URI that does not begin with http:// or https:// throws an exception.

If an http function times out, it throws a socket received exception (SVC-SOCRECV).

If you expect the request body from this http function to be processed by another application (via a web service, for example), you should specify a content-type header. If no content-type header is specified, the content type defaults to text/plain.

Example

(: Send a PUT request to insert a document into the database
 : using the MarkLogic REST Client API /documents endpoint. The
 : PUT body contains serialized XML that becomes the content of
 : the new document. The data for the PUT body is passed as 
 : serialized XML in the options parameter.
 :)
xdmp:http-put("http://example.com:8000/v1/documents?uri=my.xml"
     <options xmlns="xdmp:http">
       <authentication method="digest">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
       <headers>
         <Content-type>application/xml</Content-type>
         <Accept>application/xml</Accept>
       </headers>
       <data>{
         xdmp:quote(<mydata>this is my content</mydata>)
       }</data>
     </options>)

(: MarkLogic returns the response from the HTTP server. In this case,
 : a response similar to the following:
 :
 : <response xmlns="xdmp:http">
 :   <code>204</code>
 :   <message>Content Updated</message>
 :   <headers>
 :     <server>MarkLogic</server>
 :     <content-length>0</content-length>
 :     <connection>Keep-Alive</connection>
 :     <keep-alive>timeout=5</keep-alive>
 :   </headers>
 : </response>
 :)

Example

(: Send a PUT request to insert a document into the database
 : using the MarkLogic REST Client API /documents endpoint. The
 : PUT body contains serialized XML that becomes the content of
 : the new document. The data for the PUT body is passed as 
 : an XML node in the 3rd parameter.
 :)
xdmp:http-put("http://example.com:8000/v1/documents?uri=my.xml"
     <options xmlns="xdmp:http">
       <authentication method="digest">
         <username>myname</username>
         <password>mypassword</password>
       </authentication>
       <headers>
         <Content-type>application/xml</Content-type>
         <Accept>application/xml</Accept>
       </headers>
     </options>,
     <mydata>this is xml for the PUT body</mydata>)

(: MarkLogic returns the response from the HTTP server. In this case,
 : a response similar to the following:
 :
 : <response xmlns="xdmp:http">
 :   <code>204</code>
 :   <message>Content Updated</message>
 :   <headers>
 :     <server>MarkLogic</server>
 :     <content-length>0</content-length>
 :     <connection>Keep-Alive</connection>
 :     <keep-alive>timeout=5</keep-alive>
 :   </headers>
 : </response>
 :)

Powered by MarkLogic Server | Terms of Use | Privacy Policy