2. Enterprise Integration Patterns

javascript

Version

Executes a Javascript. The script can access and manipulate data from the request and response. Use this or the Groovy plugin to extend the functions of Membrane by scripting. See the samples in examples/javascript.

Example Configuration

api:
port: 2000
flow:
- response:
- javascript:
src: |
var body = JSON.stringify({
foo: 7,
bar: 42
});


Response.ok(body).contentType("application/json").build();
- return: {} # Do not forward, return immediately
api:
   port: 2000
   flow:
     - response:
         - javascript:
             src: |
               var body = JSON.stringify({
               foo: 7,
               bar: 42
               });

               Response.ok(body).contentType("application/json").build();
     - return: {} # Do not forward, return immediately

Syntax

javascript:
location: <string>
src: <string>
javascript:
  location: <string>
  src: <string>

Attributes

NameRequiredDefaultDescriptionExamples
locationfalseN/AA file or URL location where the content that should be set as body could be foundconf/body.txt
srcfalse---

Can be used in