I have a rest api that has many parameters via the query string. I am wondering if someone knows of a design pattern or has a nice way of organizing all the parameters (Objects, functions, array, json). Right now I am parsing and validating all my parameters in the same function, very ugly code.
Ideally I would like some way to handle the parameters similar to a database ORM or even a config file/array/json. However, I have tried to come up with a solution to this without any luck.
Any insight would be appreciated!
Example of my thoughts:
<?php ... $parameters = [ // ?fields=id,name 'fields' => [ 'default' => ['id', 'name'], 'valid' => ['id', 'name', 'date], 'type' => 'csv', // list of values (id & name) 'required' => ['id'], 'replace' => ['title' => 'name'], // if the database & api names don't match 'relation' => null, // related database table ], // ?list=true 'list' => [ 'default' => ['false'], 'valid' => ['true', 'false'], 'type' => 'boolean' // single value (true or false) 'required' => [], 'replace' => [], // if the database & api names don't match 'relation' => 'category', // related database table ], .... ];