Requests on CoAP resources

Mule flows use the CoapClient Connector to do requests on resources made available by CoAP servers. For each type of CoAP request ( GET, PUT, POST, DELETE) the connector has a mule message-processor available. The message-processors are described in the sections below .

The message-processors reference a <coap-client:config/> element, that configures a number of CoAP communication parameters that will be used when issuing CoAP requests. On the message-processors the CoAP resource is defined that will be requested during execution of the Mule flow. The resource is addressed using server host and port, the path of the resource and - optionally - query-parameters. The host and port need only to be set when they differ from the defaults in the <coap-client:config/> element. The confirmable attribute defines whether the server must confirm the request..

The payload of the CoAP request is obtained from the Mule-message payload. Its type will determine what conversion is done. A byte array type will be used as is, where other payload types are transformed to byte array equivalent to calling toString().getBytes( UTF_8 ).

The message-processors return the response of the CoAP request. The payload of the Mule-message contains the payload of the CoAP response as byte array - if any. When the server has responded on the request within time-out, the inbound-property coap.response.code contains the response category retuned by the CoAP server. The complete list of response codes can be found in the section called “Response codes”. When no timeout occurs and the response code indicates a successful processing of the request, the inbound-property coap.response.success has the value true, otherwise the value will be false. The Mule-flow can use these properties to act appropriately on the different responses.

The CoAP protocol provides for options that can be added to the CoAP messages. The CoapClient Connectors message-processors supports these. CoAP Options on a request can be set by using outbound-properties. The Mule-flow has to set these on the Mule-message before the message-processor is called. Options contained in CoAP responses are made available as inbound-properties in the Mule-message returned.

For a complete list of message properties, see the section called “Message Properties”.

The Get message-processor requests the contents of a CoAP resource.

In the example below the contents of the resource /query is requested. Some optional query parameters are defined on the request. The content-type that the Mule-flow wishes to receive is given in the outbound-property coap.opt.accept.

The response is evaluated by the Choice-Router that checks whether the request succeeded using the coap.response.success and coap.response.code inbound-properties.


The Put message-processor requests a server to set new contents on a CoAP resource.

In the example below new contents for the resource /test is requested. The content-type of the request payload is given in the outbound-property coap.opt.content_format.

The response is evaluated by the Choice-Router, which checks whether the request succeeded using the coap.response.success and coap.response.code inbound-properties. The 2.04 value of the response code indicates that the server has changed the resource.


The Post message-processor requests to create a new resource on a CoAP server. The message-payload will be used as the contents of the resource that is created.

In the example below a request is issued to add a new child resource to the /test resource. The content-type of the request payload, that should become the resources content, is given in the outbound-property coap.opt.content_format.

The response is evaluated by the Choice-Router that checks whether the request succeeded using the coap.response.success and coap.response.code inbound-properties. The 2.01 value of the response code indicates that the server has created the resource.


The Delete message-processor requests to delete a resource on a CoAP server.

In the example below a request is issued to delete the /test resource.

The response is evaluated by the Choice-Router that checks whether the request succeeded using the coap.response.success and coap.response.code inbound-properties. The 2.02 value of the response code indicates that the server has deleted the resource.