Connecting to the XNAT REST API

There are a number of different options for connecting to the XNAT REST API, ranging from your a web browser to basic access tools like curl, wget, etc to custom Java, Perl or Python solutions.

Addressibility

XNAT installations are preconfigured to have the REST API accessible under the /data folder from the server URL. Your individual site may need the port, or the webapp name (depending on how you configured it), or neither. The REST api is accessible using the same URL as you would use to access your site through a web browser.

If your site is accessible at http://machine101:8080/xnat then you would need to prefix your REST urls with http://machine101:8080/xnat/data/.... Similarly, if your site is addressable at http://central.xnat.org, then you would prefix it with http://central.xnat.org/data/...

Connection tools

XNAT REST Tools
The XNAT team has some developed some simple java based tools which can be used as command prompt tools to access the REST API.

  • XNATRestClient
    The XNATRestClient is built specifically to facilitate user interaction with the REST API from the command prompt.
XNATRestClient -host http://central.xnat.org -u USER -p PASS -m GET|POST|DELETE|PUT -remote "/data/archive/projects?format=xml"

Curl
Most UNIX operating systems come pre-installed with 'Curl' which is a tool for transferring data to or from a server. Because XNAT Servers are secured, you will need to provide a username and password to access the api.

curl -u USERNAME:PASSWORD http://central.xnat.org/data/archive/projects?format=xml

For more information on using curl, please review its documentation.

wget
Wget is an additional UNIX tool for retrieving files from a remote server.

wget --http-user=USER --http-user=PASS --auth-no-challenge http://central.xnat.org/data/archive/projects?format=xml

If your server is not configured appropriately, you may need the --auth-no-challenge attribute for the login to proceed normally.

$label.name