(Quick Reference)

Moab REST Service

The Moab REST service may be used to access the MWS RESTful API (see Resources) in plugins. All "requests" made through this service are internal only and no data is actually transmitted over the network. See Accessing REST Resources for more information.

The moabRestService property will be injected with a class of type IMoabRestService in all plugin types.

Accessing Resources

In order to access a resource, a relative URL matching that in the documentation must be used along with a HTTP method, such as GET, POST, PUT, or DELETE. The method names on IMoabRestService match the HTTP methods directly. For example, to call a GET operation on /rest/jobs, use the following code:

moabRestService.get("/rest/jobs")

Using Parameters Correctly

Although the ordering of the parameters for each method on IMoabRestService may seem confusing at first glance, this is to allow for easy use with Groovy. Examples are given below for each combination of parameters:

String url
moabRestService.get("/rest/jobs")
Map options, String url
moabRestService.get("/rest/jobs", hooks:true, contentType:"application/json")
String url, Closure data
moabRestService.get("/rest/jobs/job.1") {
	[flags:"RESTARTABLE"]
}
Map options, String url, Closure data
moabRestService.get("/rest/jobs/job.1", hooks:true, contentType:"application/json") {
	[flags:"RESTARTABLE"]
}

Options

The following options are valid in each method call supporting the options parameter:

NameTypeDefaultDescription
dataSee Valid Data Types-Specifies the body of the "request". This can be overwritten by the data Closure parameter.
hooksBooleanfalseSpecifies whether or not Pre and Post-Processing Hooks are run as part of the "request".
contentTypeStringapplication/jsonIndicates the content type used for the request.
paramsMap-Indicates URL query parameters to use for the "request", such as query, sort, proxy-user or others.

Valid Data Types

If the data Closure parameter is specified, it overwrites the data option. In each case, there are four valid types for the data option or return value of the data closure:

  1. A non-null JSON instance.
  2. A valid JSON string. This will be converted into a JSON instance.
  3. A valid Map instance. This will be converted into a JSONObject instance.
  4. A valid List instance. This will be converted into a JSONArray instance.

A JSONException may be thrown if the JSON string is invalid or the Map or List contains values that cannot be serialized to JSON.