(How) Can filters / parameters be used with a database-connected service in Apigility?

As the Apigility documentation ( REST Service Tutorial -> Create a REST Service -> [infobox] Code-Connected vs DB-Connected services

) says that the built-in functionality for DB-connected services is "faster application development (RAD) or prototyping tools."

Ok, now I am developing a very small application and I think this prototyping capability might be enough. But even this little app needs a simple filtering / request for parameterization like: items by name = 'foo'

, items by id < x and id > y

, stuff like that.

Do database related services provide filtering? If so, how to deal with this?

+3


source to share


1 answer


You are going to use the zf validation package for this (see https://apigility.org/documentation/modules/zf-content-validation ).

With the content validator, you can define inbound filters in the module's configuration section and specify which inbound filter to use to validate your service requests.

For example (from the documentation):



'zf-content-validation' => array(
    'Application\Controller\HelloWorld' => array(
        'input_filter' => 'Application\Controller\HelloWorld\Validator',
        'POST' => 'Application\Controller\HelloWorld\CreationValidator',
    ),
),


'input_filter_specs' => array(
    'Application\Controller\HelloWorldGet' => array(
        0 => array(
            'name' => 'name',
            'required' => true,
            'filters' => array(
                0 => array(
                    'name' => 'Zend\Filter\StringTrim',
                    'options' => array(),
                ),
            ),
            'validators' => array(),
            'description' => 'Hello to name',
            'allow_empty' => false,
            'continue_if_empty' => false,
        ),
    ),
),

      

This config will check that requests to your HelloWorld controller will include a "name" parameter, which is a string, and additionally trim whitespace for you. If your request had a request parameter ?name=foo

, your controller will receive foo

for the name parameter. Or, if your request does not include a name parameter, you will receive an ApiProblem response indicating that the request failed validation.

+1


source







All Articles