Call it with a query parameter name:
http://localhost:2000?name=Joe
<api port="2000">
<request>
<template contentType="text/plain">Hello ${params.name}!</template>
</request>
<return statusCode="200"/>
</api>
Call it with the answer.
http://localhost:2000?answer=42
<api name="JSON" port="2000" method="GET">
<request>
<template contentType="application/json" pretty="yes">
{
"answer": ${params.answer},
"foo": 7
}
</template>
</request>
<return statusCode="200"/>
</api>
Send a POST with an XML body content to the api.
<api port="2000">
<request>
<template location="template.xml"/>
</request>
<return statusCode="200"/>
</api>
If the filename of the template ends with .xml you can use the elements from the gsp namespace. See GroovyXMLTemplate Engine
<destinations xmlns:gsp='http://groovy.codehaus.org/2005/gsp'>
<gsp:scriptlet>def answer = 42;</gsp:scriptlet>
<answer><gsp:expression>answer</gsp:expression></answer>
<gsp:scriptlet>
import groovy.xml.XmlSlurper
def xml = new XmlSlurper().parseText(body)
</gsp:scriptlet>
<gsp:scriptlet>xml.children().each { </gsp:scriptlet>
<destination><gsp:expression>it</gsp:expression></destination>
<gsp:scriptlet> } </gsp:scriptlet>
</destinations>
Name | Required | Default | Description | Example |
---|---|---|---|---|
pretty | false | - | - | - |
location | false | - | - | - |
contentType | false | - | - | - |
The following variables can be accessed within a template.
Name | Class | Description |
---|---|---|
exc | com.predic8.membrane.core.exchange.Exchange | The Exchange class provides, among others, access to the Request, Response and their corresponding Headers. |
message | com.predic8.membrane.core.http.Message | Message is the superclass of a request or a response. Depending on the flow the message contains data from the request or the response. |
header | com.predic8.membrane.core.http.Header | The header object allows access to the HTTP header fields. You can remove, add and change fields. |
body | com.predic8.membrane.core.http.Body | The body of the message. |
json | java.util.Map | If the message contains a body of the type application/json this varible will contain the JSON as a Map. Use it only to read the JSON document. |
flow | com.predic8.membrane.core.interceptor.Flow | REQUEST or RESPONSE |
properties | java.util.Map | The properties of the exchange object. |
spring | org.springframework.context.ApplicationContext | The Spring application context hosting the router instance (or null, if the router is not hosted by Spring). |