There are two ways to use GET params as API arguments:
- In the class that the endpoint refers to (e.g. your Card component class). Basically this means that instead of — or in addition to — regular constructor arguments you would also check provided GET params.
- Alternatively you can hook into the
WireframeAPI::prepareArgs()
method and merge GET params with existing arguments — though be sure to also filter them so that they can only contain useful/expected values!
Here's an example of hooking into the prepareArgs() method and merging GET argument called "some_variable" with any existing arguments:
$api->addHookAfter('prepareArgs', function(HookEvent $event) use ($input) {
$event->return = array_merge($event->return, [
$input->get->bool('some_variable'),
]);
});
Note that while in the example above we could've also allowed all GET params simply by merging $event->return
with $input->get->getArray()
, allowing users to freely pass arguments of their choice to your endpoint could be potentially dangerous.