Layer7 API Management

  • 1.  [URGENT] Throw a custom response from Events

    Posted Nov 07, 2017 10:27 AM

    If we are putting a custom validation that will be defined by us and for that, I am using the Early Event. Here is my scenario  

     

    It is not the real scenario but my scenario is very similar to this - 

    Suppose if there is a POST request to a table and I want to check that,

     

    if newRow.name already exists in the table then return a JSON response to the user that it is already there with a custom statusCode + meaningful message into that JSON.

     

     

    Is this possible using reactive logic? As I have to check this when a user is going to create a record for that table.

     

    Or any other alternative for this?

     

    Please help ASAP. Thanks in advance.

     

    cc -  tarma06



  • 2.  Re: [URGENT] Throw a custom response from Events

    Posted Nov 09, 2017 11:59 AM

    From a database perspective - you could add a unique index on 'name' - this would force the database to throw a unique constraint violation. 

    From a rules world -

    1) you would create a parent table with 2 columns - name and count. 

    2) Then create a virtual relationship (schema page in LAC) between your table and this new parent table.  The join is on name

    3) Add a rule on this new parent table to count children 

    4) Add a rule - managed parent on the child table (select the parent table relationship) - aka Insert Parent if Not Found

    5) Add a Validation on this new parent table - if (row.count > 1) {return false;} else {return true;}

    message: This is a duplicate name: {name}

     

    Now when you insert a name - the rules will insert a name into the parent (count = 1) - if a second name is inserted - the count > 1 and the validation rules fires with a message (instead of a database constraint validation error).   



  • 3.  Re: [URGENT] Throw a custom response from Events

    Posted Nov 14, 2017 07:56 AM

    Sorry, but I think you didn't get my scenario. Please ask if you have any doubts.



  • 4.  Re: [URGENT] Throw a custom response from Events

    Posted Nov 26, 2018 04:20 PM

    Hi -   What version of Live API Creator are you using? In 5.0, we now allow you to customize the error code in your response. The database constrain violation would be a common approach to find out whether the record based on the "name" exists and you would then implement an Error Event Handler to catch the database error (no rules needed here), throw the appropriate error code/message back to the client. 

    For more details, see:  Release Notes - CA Live API Creator - 5.0 - CA Technologies Documentation