API and Data Validation

Welcome Forums General PowerShell Q&A API and Data Validation

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #171409

    Participant
    Topics: 10
    Replies: 11
    Points: 122
    Rank: Participant

    Hi all

    I have written a script (let's call it X.ps1) which pulls data from one system via a small API wrapper (A.psm1), manipulates it and then sends it via POST or PUT to a second system, via another API wrapper (B.psm1).

    A.psm1 > X.ps1 > [do some stuff] > B.psm1

    System B has some quirks, which mean that I need to validate the output from System A before sending it. E.g. if "Gender" is not "M" or "F", the request fails – this often causes issues if the field is empty/null in System A. Adding basic validation is simple enough, but I am not sure where to put it. Should X.ps1 check the data before invoking commands in B.psm1? Or should B.psm1 do the validation and send back warnings/errors to X.ps1 ?

    Cheers!

  • #171427

    Participant
    Topics: 1
    Replies: 23
    Points: 164
    Helping Hand
    Rank: Participant

    I would manipulate the data in X so that it runs B with arguments. Tell B which parameters are mandatory and validate them.

  • #171439

    Participant
    Topics: 10
    Replies: 11
    Points: 122
    Rank: Participant

    So, to use my example, if X retrieves a record from A which includes Gender=null, it should be passed to B where validation will occur. X should then use try/catch to deal with the resulting validation error in B, rather than X checking the contents of the Gender field itself. This approach means X doesn't need to be aware of any changes to B (e.g. B may be updated to accept Gender=null later on).

    Does that sound about right?

You must be logged in to reply to this topic.