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.ThemoabRestService
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 theoptions
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 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 thedata
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 non-null JSON instance.
- A valid JSON string. This will be converted into a JSON instance.
- A valid Map instance. This will be converted into a JSONObject instance.
- 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.