Suppose there is a custom API to get giftcode.
The API has Referance and Amount as requird parameters whereas Activated and Quantity as optional parameters
If URL is:
http://ruteurl/rest/V1/giftcode/request?reference=XYZ&amount=50
It should run assuming Activated and Quantity to be 1 by default
If URL is:
http://ruteurl/rest/V1/giftcode/request?reference=XYZ&amount=50&activated=0&quantity=5
the values shoud be as provided in url and not the default ones.
How can we do this using php? (My platform is Magento 2)
2
Answers
This validation can be done in the server side. Make it as a PHP utility.
Query params available in $_GET.
Use the Null coalescing operator (??) to get a default value for a non-existing
key-value
in an array. For example: