Anyone can easily plug in a custom logic to WSO2 API manager to process request/response payloads using Mediation Extensions feature. Following two custom sequences can be used to evaluate payload with content type application/x-www-form-urlencoded and application/json
1. application/x-www-form-urlencoded
2. application/json
1. application/x-www-form-urlencoded
<?xml version="1.0" encoding="UTF-8"?> <sequence xmlns="http://ws.apache.org/ns/synapse" name="form_data"> <property name="LastName" expression="//xformValues//lastName/text()"/> <log level="custom"> <property name="Log: LastName" expression="get-property('LastName')" /> </log> </sequence>
Sample requestcurl -k -X POST -H 'Authorization: Bearer 95b59dfc-aae1-3b85-aec7-93a0471fea42' -H "Content-Type: application/x-www-form-urlencoded" 'https://172.21.0.1:8243/test/1/*' -d 'lastName=chamila'
2. application/json
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="json_payload">
<property expression="json-eval($.lastName)" name="LastName"/>
<log level="custom">
<property name="Log: LastName" expression="get-property('LastName')" />
</log>
</sequence>
Sample requestcurl -k -X POST -H 'Authorization: Bearer 95b59dfc-aae1-3b85-aec7-93a0471fea42' -H "Content-Type: application/json" 'https://172.21.0.1:8243/test/1/*' -d '{"lastName":"chamila"}