irach15 Here is some coding example. Being a developer is not fun 🙂 I can share your pain.
<#compress>
<#assign header_names = http.request.headerNames />
<#assign token_from_request = "" />
<#if header_names?seq_contains("API-TOKEN")>
<#assign token_from_request = http.request.getHeader("API-TOKEN") />
</#if>
<#assign token_from_setting = community.settings.name.get("your.community.settings.list.variable", "") />
<#if token_from_request == token_from_setting>
<#assign query = "........." />
<#assign items = restadmin("2.0", "/search?q=${query?url}").data.items![] />
{
"data": [
<#list items as item>
{
// some json print out coding
}
</#list>
]
}
<#else>
{"error": "invalid request"}
</#if>
</#compress>
<#compress>
<#assign header_names = http.request.headerNames />
<#assign token_from_request = "" />
<#if header_names?seq_contains("API-TOKEN")>
<#assign token_from_request = http.request.getHeader("API-TOKEN") />
</#if>
<#assign token_from_setting = community.settings.name.get("your.community.settings.list.variable", "") />
<#if token_from_request == token_from_setting>
<#-- curl out to 3rd party -->
<#assign response = http.client.request("some url").header("Content-Type","application/x-www-form-urlencoded").parameter("p1", "v1").parameter("p2", "v2").post()/>
<#--some error condition checks-->
<#--success or error JSON print out-->
<#else>
{"error": "invalid request"}
</#if>
</#compress>