Problem

You want a quick & dirty way to work with XQuery or SJS. Query Console is great for interactively building stuff and for queries, but sometimes the direct-to-filesystem cuts out QC middle man, and also with this approach you can do things with your output, like pipe it to a file, which is a pain with QC.

Solution

Applies to MarkLogic versions 8+

Put this in a file called “make-app”:

#!/bin/bash
ROOT=`pwd`
NAME=$1
PORT=$2
curl --digest --user admin:admin -X POST -Hcontent-type:application/json \
  -d"{\"server-name\":\"$NAME\",\"group-name\":\"Default\",\"server-type\":\"http\",\"content-database\":\"Documents\",\"port\":$PORT,\"root\":\"$ROOT\",\"authentication\":\"application-level\",\"default-user\":\"admin\"}" \
  https://localhost:8002/manage/v2/servers

Run it like this:

make-app TEST 9999

Now you create a file, say, x.xqy, and run it

curl --digest --user admin:admin https://localhost:9999/x.xqy

Required Privileges:

  • https://marklogic.com/xdmp/privileges/manage-admin
  • https://marklogic.com/xdmp/privileges/manage-admin

Discussion

This recipe uses the Management API to create a new application server that looks at the file system for source code. Specifically, it looks at the directory you’re in when you run the make-app script. The app server will use the Documents database for content; the app server name and port are specified as parameters to the script.

Notice that the authentication is set to “application-level” and the default user is set to “admin”. This effectively turns off security: the admin user can access all content and run all functions.

Once the app server has been created, you can save any file and easily run it with a curl command or even with a browser (using something like POSTman if you want to send requests with verbs other than GET).

The MarkLogic REST API requires an app server with a modules database, so this won’t work for testing out REST extensions or transforms.

Learn More

Application Developer's Guide

Read the methodologies, concepts, and use cases related to application development in MarkLogic Server, with additional resources.

MarkLogic Developer Learning Track

Want to build that awesome app? Get off the ground quickly with the developer track, with instructor-led and self-paced courses.

Getting Started Video Tutorials for Developers

This series of short videos tutorials takes developers who are new to MarkLogic from download to data hub, fast.

This website uses cookies.

By continuing to use this website you are giving consent to cookies being used in accordance with the MarkLogic Privacy Statement.