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.
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.
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.
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.
Like what you just read, here are a few more articles for you to check out or you can visit our blog overview page to see more.
The MarkLogic Optic API makes your searches smarter by incorporating semantic information about the world around you and this tutorial shows you just how to do it.
Are you someone who’s more comfortable working in Graphical User Interface (GUI) than writing code? Do you want to have a visual representation of your data transformation pipelines? What if there was a way to empower users to visually enrich content and drive data pipelines without writing code? With the community tool Pipes for MarkLogic […]
Rest and Spread Properties in MarkLogic 10 In this last blog of the series, we’ll review over the new object rest and spread properties in MarkLogic 10. As mentioned previously, other newly introduced features of MarkLogic 10 include: The addition of JavaScript Modules, also known as MJS (discussed in detail in the first blog in this […]
Don’t waste time stitching together components. MarkLogic combines the power of a multi-model database, search, and semantic AI technology in a single platform with mastering, metadata management, government-grade security and more.
Request a Demo