I'm in search of the correct format a server should use for the arguments array.
I noticed the use case seems to differ from resource to resource,
certain ones work with an unnamed array:
$args[0] = value
others require a named array:
$args[key] = value
as amfserver handles them inconsistently, certain resource fail…
(services_views module only works with named arrays it seems)
(resources as node_resource seems to manipulate them further to eg. $args[0]->arg in the access callback, which is even more confusion)
so, what is the standard format of the arguments which should be fetched to a resource? is the named array the correct one?
Comments
Comment #1
g10 commentedAfter testing the services module w/ d7 (+ services_views, services_menu and amf_server) I noticed an inconsistency on how the arguments are declared in resources, and how they are handled… this, in combination w/ a faulty implementation in the amf_server, resulted in some bugs.
I would like to propose a change related to the arguments array handling of a resource:
this by providing a method in the services.module which:
- serialize the arguments in an associative array
- validates if all required arguments are present (if not, throws a services_error)
- adds the default value of optional argument, if no value is provided
this method would be called in the services_controller_execute, before checking authentication (as authentication uses the arguments).
The args array in the declaration of a resource would be able to be declared in both ways: an associative/named array OR an indexed array
indexed array:
current implementation in services module for resources:
associative array:
the services_views implementation (and proposed for services_menu)
Benefits:
- server implementations don't have to worry about serialization and validation of arguments (no repeated code/functionality, responsibility is with the core services module who executes a resource)
- arguments are passed in a consistent way to the access callbacks of the resources (as one method handles all the calls in the same way, opposed to each server having another implementation, and as a result be prone to bugs)
As I've only recently switched to the 3.x branch, I'm still not 100% grasping the mindset and the intended structure. As a result my first thought was that there was an issue with the services_views module ( #1167354: $args empty in access callback ), after identifying a bug in the amf_server ( #1218070: correct argument parsing ) I assumed the services_views module was working correctly ( although, services_views declares the args array with an associative array, opposed to an indexed array as the services module ). And finally by optimizing the services_menu module ( #1222098: Invitation to merge with branch on GitHub ) I realized the issue is simply with the fact that there is no consensus on how a server implementation should serialize the passed arguments.
As I'm not testing on the rest_server, any feedback/insights on possible implications are welcome.
Comment #2
kylebrowning commentedIm not 100% sure how I feel adding this to services.module, but right now its up to the server to decide how the arguments are processed and worked out and we kind of like it that way.
REST server handles it like this.
At any rate, if we do implement something like this into services.module instead of at the services level, its not happening anytime soon as we still don't have a 3.x release.
Comment #3
g10 commentedThanks for the feedback, I realize there is some server specific argument handling to be done…
From the point of view of amf_server, there is no path/param/data differentiation, which led me to believe all of the code for serialization would be duplicated in each module.
The only part which actually has to be duplicated (in each server implementation) is the default value / missing arguments check:
This functionality is separate from the argument serialization, and should be performed in the same way for each call (independent of server implementation)
Handling this would prevent server implementations to pass through an argument array in a wrong format,
and avoid resources to have to implement this kind of tricks:
(additionally the arguments could be cast to their proper data type)
IMHO, this is the responsibility of the services.module (to at least enforce an uniform argument array to be passed by the servers).
Comment #4
g10 commentedAfter a closer look on how rest_server handles the arguments, I realize now that this should be handled by the servers themselves (the needs of the rest_server are too specific to have a general approach to this)
The patch in #1218070: correct argument parsing brings the argument handling in line with the rest_server implementation