Friday, September 5, 2014

How to use validations on field in Apigility

Validation in Apigility:

Its very easy to use validation on the fields in case of Apigility. For this we have to use the following steps.

If we have fields like this:

Content Validation Required Field
Then if we send request

POST /contact HTTP/1.1 Accept: application/json Content-Type: application/json; charset=utf-8 { "name": "Ralph", "email": "foo@bar.com" }
 It will give the following response
HTTP/1.1 422 Unprocessable Entity Content-Type: application/problem+json { "detail": "Failed Validation", "status": 422, "title": "Unprocessable Entity", "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html", "validation_messages": { "age": { "isEmpty": "Value is required and can't be empty" } } }
Because age is not there.

For age's validation if we want it should be digit & should be between in 1 to 120 then we will use the following.

Content Validation Multiple Validators
 Thus we can use validations in fields

Thanks

No comments:

Post a Comment