We’ve joined forces with Smartlogic to reveal smarter decisions—together.

Two Languages Shockingly Easy to Use With MarkLogic

As a MarkLogic consultant, my job is as often about managing MarkLogic or moving data in and out of MarkLogic as it is about the application with which the end-user interacts.  Here are two languages that don’t have large, formal MarkLogic toolkits like the DMSDK or Java Client API, but are easy to “plug in” to MarkLogic.  It’s possible to use these languages to build tools or scripts to simplify your MarkLogic work.

Why is it easy? MarkLogic is built to be standards compliant, interacting primarily over two REST APIs: a management API and a client API. Because these are standard REST APIs that can return JSON or XML responses, any language that can support REST will work with MarkLogic.  In 2017 that’s a pretty low bar, so almost every language is covered.

That said, some languages have particularly good support for
XML and HTTP (including digest authentication for projects that don’t use basic authentication). Here are two of them, and my experience integrating each with MarkLogic in particular, and RESTful management and data access in general.

Using Go With MarkLogic

The Go language – sometimes called golang – is a language introduced by Google in 2007.  I enjoy it because Go is a language I can pretty much keep in my head all at once, kind of like when I first learned C.  It’s low level and about as fast as C.  Unlike C, Go has garbage collection, reflection, and built-in concurrency.  There is a rich tooling community around Go.  Where Go really shines is in the container space, where Go is to containers what C is to Unix.

To use Go with MarkLogic there’s only one dependency, and that’s only if you’re using the Digest authentication method.  I also created my own version to which I’ve added header support.  The code is fairly simple, for example, let’s get a list of all the hosts in a cluster:

package main

import (
    "io"
    "os"

    digest "github.com/paul-hoehne/go-http-digest-auth-client"
)

func main() {
    req := digest.NewRequest("admin", "kat", "GET", "http://192.168.56.201:8002/manage/v2/hosts?format=json", "")
    resp, _ := req.Execute()
    io.Copy(os.Stdout, resp.Body)
}

What makes Go attractive is that go programs can be run on the command line (using the “go run” command) or statically compiled into binaries with no runtime requirements. The binaries are easily cross-compiled to other architectures, supporting Windows, Linux x64, Linux ARM, and MacOS with little effort. Because Go has no runtime, is statically compiled, and relatively fast, it may become the language of choice for containers that include nothing but a minimal Linux userland.

Using Python With MarkLogic

Python is another language that integrates well with MarkLogic’s JSON API support.  The only dependency needed is the requests package.

Of course, MarkLogic plugs nicely into Python.  As an example, there is the MarkLogic Python management API.

import requests
from requests import auth

me = auth.HTTPDigestAuth("admin", "kat")
resp = requests.get("http://192.168.56.201:8002/manage/v2/hosts?format=json", auth=me)
print(resp.json())

Four lines of code!

Because the “json” method on the response from the requests package returns a Python dictionary, the data is immediately usable. Python is available for every computer architecture from a Raspberry Pi to a z/OS mainframe.  Because Python is everywhere, has an incredibly rich eco-system, is very approachable to even programming novices, is included with Linux, supported in Visual Studio for Windows, and is interpreted, it is a great choice for system administration and data movement tasks.

Another thing that makes Python so attractive is that it’s extremely popular in statistics and data science.  Libraries like SciPi, Pandas, Numpy, and Keras make machine learning with Python approachable to a wide number of people.  In the data science community, the Jupyter notebook tool based on Python is becoming ubiquitous.  In addition to data science and machine learning, Python has libraries for almost everything. As an interpreted language, there is no compile phase or management of executables separate from source code.

Other Languages That Work With MarkLogic

Java, Node, cURL, Ruby, C++ … The list of language and tools usable with MarkLogic is essentially limitless.  While Java and Node have specialized, idiomatic APIs into MarkLogic, those MarkLogic-supplied libraries actually call the same REST API that Go, Python, or other languages would use.  Plugging MarkLogic directly into your latest Python data science project or Rails application may be simpler, quicker, and easier than you think.

Start a discussion

Connect with the community

STACK OVERFLOW

EVENTS

GITHUB COMMUNITY

Most Recent

View All

Facts and What They Mean

In the digital era, data is cheap, interpretations are expensive. An agile semantic data platform combines facts and what they mean to create reusable organizational knowledge.
Read Article

Truth in ESG Labels

Managing a portfolio of investments for your client has never been simple - and doing so through an ESG lens raises the complexity to an almost mind-boggling level. Learn the signs your team has hit the wall with current tools - and how a semantic knowledge graph can help.
Read Article

4 Signs You’ve Got a Transaction Reconciliation Challenge

Many firms manage transaction reconciliation using smart people armed with spreadsheets - but that doesn't scale well. Learn what to look for, to know if you're creating new forms of risk for your firm.
Read Article
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.