Javascript Validation

In my usecase i have 15+ resource paths where I need to perform required field validation. Majority of resource paths are having the same required fields but few are having additional required fields.

Any suggestions on the approaches listed below.Which will be the best approach?

Approach 1 : Use single JS

  • Which has common validations and
  • Use if()else() for the resource path for specific required field validation

Approach 2 : Use two JS

  • One for common validation
  • One for handling the additional validation for specific resource path

Approach 3 : Use Multiple JS

  • One for common validation
  • One for each resource path which has additional Validation
1 1 882
1 REPLY 1

@maivizhi ,

Here is what i think about same, I might not be right but just would like share my opinion,

Approach 1 :

  • You will find everything in one place
  • It will become too complex to manage moving forward
  • More computation in Javascript for each & every API call. I heard somewhere that Javascript in Apigee is costly when it comes to performance.
  • I don't recommend this.

Approach 2 :

  • It's more or less similar to Approach 1 except code split into two files
  • I don't see any performance improvement from Approach 1
  • Code management is better than Approach 1

Approach 3 :

  • Better than 1 & 2
  • All common validations goes into preflow / postflow
  • Additional validations are executed whenever resource matches
  • At the end of the day, less amount of javascript executed during run time api call. If / Else is handled by Apigee in routing resources.
  • I believe this should be the one you should take.