UNPKG

joule

Version:

Node implementation of Mule for creating REST services

226 lines (225 loc) 8.84 kB
{ "globalComponents": { "setHeaders": { "type": "setHeaders", "headers": { "test": "testing", "test2": "testing2" } }, "setHeadersLogger": { "type": "logger", "message": "Headers: $$JSON.stringify(res._headers)$$" } }, "apps": [ { "host": "localhost", "port": 8081, "routes": [ { "path": "/setHeaders", "components": [ "setHeaders", "setHeadersLogger", { "type": "setPayload", "value": "Custom response headers have been set. You'll need to examine the response object to see them." } ] }, { "path": "/setVariable", "components": [ { "type": "setVariable", "name": "passedInId", "value": "$$req.getParam('id')$$" }, { "type": "logger", "message": "id: $$res.getVariable('passedInId')$$" }, { "type": "setPayload", "value": "You passed in id: $$res.getVariable('passedInId')$$" } ] }, { "path": "/customFunction", "components": [ { "type": "customFunction", "require": "node_modules/joule/sample/sampleCustomFunctions", "function": "customFunction" }, { "type": "logger", "message": "myVar: $$res.getVariable('myVar')$$" }, { "type": "setPayload", "value": "myVar: $$res.getVariable('myVar')$$" } ] }, { "path": "/parseTemplate", "components": [ { "type": "parseTemplate", "file": "node_modules/joule/sample/sample.txt", "attrs": {"id": "$$req.getParam('id')$$"}, "setPayload": true } ] }, { "path": "/parseTemplate2/:id", "components": [ { "type": "parseTemplate", "file": "node_modules/joule/sample/sample.txt", "attrs": {"id": "$$req.getParam('id')$$"}, "setPayload": true } ] }, { "path": "/webServiceConsumer", "components": [ { "type": "webServiceConsumer", "endPoint": "http://api.data.gov/census/american-community-survey/v1/2011/populations/states?api_key=DEMO_KEY", "responseType": "json", "setPayload": true }, { "type": "logger", "message": "response: $$res.getPayload()$$" } ] }, { "path": "/webServiceConsumerDynamicUrl", "components": [ { "type": "webServiceConsumer", "endPoint": "http://api.data.gov/census/american-community-survey/v1/$$req.getParam('year')$$/populations/states?api_key=DEMO_KEY", "responseType": "json", "setPayload": true }, { "type": "logger", "message": "response: $$res.getPayload()$$" } ] }, { "path": "/webServiceConsumerBadEndPoint", "components": [ { "type": "webServiceConsumer", "method": "get", "endPoint": "http://bad.domain.kom", "responseType": "json", "setPayload": true } ] }, { "path": "/customErrorHandler", "components": [ { "type": "parseTemplate", "file": "non-existent-file-to-force-an-error", "attrs": {} }, { "type": "customErrorHandler", "require": "node_modules/joule/sample/sampleCustomFunctions", "function": "errorHandler" } ] }, { "path": "/genericErrorHandler", "components": [ { "type": "parseTemplate", "file": "non-existent-file-to-force-an-error", "attrs": {} } ] }, { "path": "/choiceHandler", "components": [ { "type": "choice", "conditions": [ { "if": "$$req.getParam('id') === 'hello'$$", "then": [ { "type": "setVariable", "name": "response", "value": "HELLO" } ] }, { "if": "$$req.getParam('id') === 'hello2'$$", "then": [ { "type": "setVariable", "name": "response", "value": "HELLO2" } ] }, { "if": "$$true$$", "then": [ { "type": "setVariable", "name": "response", "value": "Invalid param: $$req.getParam('id')$$" } ] } ] }, { "type": "logger", "message": "ID: $$res.getVariable('response')$$" }, { "type": "setPayload", "value": "$$res.getVariable('response')$$" } ] } ] }, { "host": "localhost", "port": 8082, "routes": [ { "path": "/json", "components": [ { "type": "setPayload", "value": { "1": "test", "2": "test2" } } ] } ] } ] }