xdmp.httpPut

xdmp.httpPut(
   uri as String,
   [options as Object?],
   [data as Node?]
) as Sequence

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. This function supports the following options, plus the options from the xdmp.httpGet 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.httpGet $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 JSON document into the database
// using the MarkLogic REST Client API /documents endpoint. The
// PUT body contains serialized JSON that becomes the content of
// the new document. The data for the PUT body is passed as serialized
// JSON in the options parameter.

'use strict';
fn.head(
  xdmp.httpPut(
    'http://example.com:8000/v1/documents?uri=my.json',
    { authentication : {
        method : 'digest',
        username : 'myusername',
        password : 'mypassword'
      },
      headers: {
        'Content-type': 'application/json',
        Accept: "application/json"
      },
      data: xdmp.quote({this: 'is my document content'})
    }
));

// MarkLogic returns the response from the HTTP server. In this case,
// a response similar to the following:
//
// {"code":201, 
//  "message":"Created", 
//  "headers":{
//    "location":"/v1/documents?uri=my.json", 
//    "server":"MarkLogic", 
//    "content-length":"0", 
//    "connection":"Keep-Alive", 
//    "keep-alive":"timeout=5"
//  }}

Example

// Send a PUT request to insert a JSON document into the database
// using the MarkLogic REST Client API /documents endpoint. The
// PUT body contains serialized JSON that becomes the content of
// the new document. The data for the PUT body is passed as a 
// JavaScript object in the data parameter. The JavaScript will be
// converted to serialized JSON when MarkLogic constructs the body;
// You could also pass a JSON node or other node type.

'use strict';
fn.head(
  xdmp.httpPut(
    'http://example.com:8000/v1/documents?uri=my.json',
    { authentication : {
        method : 'digest',
        username : 'myusername',
        password : 'mypassword'
      },
      headers: {
        'Content-type': 'application/json',
        Accept: "application/json"
      }
    },
    {this: 'is my document content'}
));

// MarkLogic returns the response from the HTTP server. In this case,
// a response similar to the following:
//
// {"code":201, 
//  "message":"Created", 
//  "headers":{
//    "location":"/v1/documents?uri=my.json", 
//    "server":"MarkLogic", 
//    "content-length":"0", 
//    "connection":"Keep-Alive", 
//    "keep-alive":"timeout=5"
//  }}

Powered by MarkLogic Server | Terms of Use | Privacy Policy