Strict Mode
Don't worry if your Request body lacks schema validation – Qyrus has a solution with strict mode in Dynamic asset to support you.
Contents
What is Strict Mode
Let's grasp this concept using an example.
Imagine your Dynamic asset has three fields company, country, and city. Now, if you try to add a fourth field called street in the request body for POST call, the request shouldn't be accepted, and an error should be shown. This is exactly what strict mode accomplishes for you!
Let's continue the above example and observe the outcomes when Strict Mode is turned on and off.
Strict Mode is on:
You can't provide extra fields in the request body.
You can't miss any existing field in the request body.
You can't change the field name in the request body.
Strict Mode is off:
You can provide extra fields in the request body.
You can remove any existing field in the request body.
You can change the field name in the request body.
Now Let's see how it works!
Usage of Strict Mode
You will discover the Strict Mode toggle on the dynamic asset page in basic mode, just like it's displayed in the image below.
Now let's check what happens when we hit Post request with the wrong request body data. In the request body, I've added an extra field which is wrong when strict mode is on.
Hit the request and see the result.
As discussed and shown in the above image, the Status Code is 500 and the Error Message is also there.
Now let's check what happens when we hit the same request again but with the strict mode is off.
As discussed and shown in the above image, Status Code is 201 and Data is created.
Pretty cool, huh? You can delve deeper into strict mode using various examples.
Related Topics
Last updated