Anushka Ekanayake
Anushka Ekanayake

Reputation: 987

How to Ignore API call with invalid json body in WSO2 API manager

I use wso2 API manager for publishing some of my APIs. But my issue is if someone send a API request with invalid json body, is it able to ignore that API call and give some error message to the requested person without sending that invalid json body to the back end. API manager version : 1.7

Could it possible to restrict user by value of role in the above json ? How to achieve this with API Manager 2.0 ?

Upvotes: 2

Views: 877

Answers (3)

sanjeewa.190
sanjeewa.190

Reputation: 360

You can refer this article on "How to validate JSON request payload in API Manager". This is exactly address your use case and only thing you need to do is add XSD to match with your request. In API Manager if you need to validate request or pre process message its always recommend to use mediation extensions available with the product.

Upvotes: 1

Abimaran Kugathasan
Abimaran Kugathasan

Reputation: 32468

Thre aren't any predefined way to achieve this requirement. But, You can customize WSO2 API Manager to cater this requirement.

You can write a custom handler which will validate the request body and return response if the request has some error rather sending to backend. You can check here on how to write a custom handler for API Manager 2.0.

Upvotes: 2

Jenananthan
Jenananthan

Reputation: 1401

In coming request will be transform to SOAP format by message builder[1].This message builder will be chosen based on the content type of incoming message.You can write your own message builder for application/json and validate the input. e.g [2]

[1]https://docs.wso2.com/display/ESB481/Working+with+Message+Builders+and+Formatters [2]https://github.com/anuruddhal/WSO2-ESB-Custom-Message-Builder/tree/master/CustomBuilder

Upvotes: 0

Related Questions