Moab Web Services > Plugins > Plugin Services > Moab REST Service

Moab REST Service

The Moab REST service may be used to access the MWS RESTful API (see Resources Introduction) in plugins. All "requests" made through this service are internal only and no data is actually transmitted over the network. See Accessing MWS 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:

Name Type Default Description
data See Valid data types -- Specifies the body of the "request." This can be overwritten by the data Closure parameter.
hooks Boolean false Specifies whether or not hooks (see Pre- and Post-Processing Hooks) are run as part of the "request."
contentType String application/json Indicates the content type used for the request.
params Map -- 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:

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

Related Topics 

© 2015 Adaptive Computing