I am new to apigee I have q requirement where in I have to validate the JSON request for mandatory fields in the JSON post request before sending it to client.
Saw some posts where TV4 is used which i am currently having difficulty in understanding. Can some one post a simple Apigee proxy example where the above requirement can be fulfilled. That will help in a better understanding of it.
Hi @Naveen Chalageri,
To learn from basic you can ignore the TV4 as of now. here are the steps for you.
- Create sample proxy
- Add JS policy to validate the request
- In the .JS file get request content using context.getVariable("request.content");
- Now you shoould be able to put some condition as this can be simple js steps.
- In else set context.setVariable("error", true);
- Add Raisefault with error = true condition
This will validate your request.
If you want to explore tv4 also, you can do it here you go with a good reference
I provided an updated solution that supports OAS 2 and 3 request validation, plus it validates required headers and query params. See: https://community.apigee.com/articles/88441/validate-json-requests-using-openapi-spec-20-or-30.html
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |