Warning: A non-numeric value encountered in /home/customer/www/archive.ricston.com/public_html/wp-content/themes/Divi/functions.php on line 5766

Normally, a RESTful interface in Mule 3.2 is created using the Jersey Module. Adding the Jersey framework to your application may be an overkill for simple RESTful interfaces. Apart from this, Mule and Jersey don’t play well together when you try to move message processing away from Jersey and into Mule. Luckily, the developers at MuleSoft have given us an alternative to Jersey for tackling simple use cases: the Rest Module.

The Rest Module provides a message processor called router that acts as a router as well as a filter. HTTP requests that have their URL path matching the router’s templateURI attribute are routed to one of the router’s child processors depending on the request’s HTTP method. Otherwise, they are ignored by the router.

In the above example, the first router only accepts messages that have a URL path matching the pattern /task/{taskId} pattern such as http://localhost:8080/task/54. GET requests are routed to the get processor’s block whereas POST requests are routed to the post processor’s block. The second router executes the get block only if messages are GET requests and the path equals to /tasks.

URI parameters are copied onto the message’s properties and may be accessed using the variable evaluator. In the example, the expression-transformer puts the taskID parameter in the message payload which is used to query/update the database.

Checkout the Rest Module documentation for installation instructions and the complete list of supported HTTP methods.