is there any sample code who can help for my below requirement.
i am publishing Rest APIs in WSO2 API Manager , i would like to intercept my own API input field validations for each API like input parameter format and value etc .If validation success then API Manager should allow the request to invoke back-end , else reject the request with error message.

I have gone though some documents and i understand we can achieve this by adding mediation extensions and custom handler, however I couldn't find any sample code for this.

<https://docs.wso2.com/display/AM140/Adding+a+Mediation+Extension>

If we are writing custom handler , should we write it for each API and do config changes in API Synapsis file? 
I would like to have a single handler which will invoke for All APIs, and handler will execute the corresponding method which is applicable for that specific API .