Hi Tobias,
thanks for Your answer.
I am fully aware we cannot encode
everything in URIs, but there's a good deal of functionality that
can be trivially encoded.
First candidate for "RESTful-ization" is obviously the RPC section of WAMP (RESTful does not really define a push interface).
My first attempt (probably misguided, since I'm not a WEB guru) would be to map URI to JSon with the following scheme:
1) remove the header, up to a conventional component (e.g.: "RESTful").
2) add request type to function name, followed by a dot ('.')
3) map all "path" components to function name substituting a dot ('.') for each delimiter (usually '/')
4) add last component of "path" as first argument.
5) for each "query" component:
5.1) if it is naked (no '=') then add it as an argument
5.2) if it is qualified (with '=') the add it as a subcomponent '{ "key" : "value" }'
5.3) double separators are special:
5.3.1) ';&' starts a subcomponent ('{')
5.3.2) ';;' ends a subcomponent ('}')
5.3.3) '&&' starts an array ('[')
5.3.4) '&;' ends an array (']')
5.4) "fragment" is a JSon string and it is appended as-is
5.5) any subcomponents or arrays still open are closed to form a "legitimate" JSon fragment.
Example:
URI: GET
http://my.server.org/RESTful/customer/12345JSon: { "procedure" : "GET.customer", "args" : [ 12345 ] }
URI: PUT
http://my.server.org/RESTful/customer/12345?discount=30JSon: { "procedure" : "PUT.customer", "args" : [ 12345, { "discount": "30 } ] }
URI: GET
http://my.server.org/RESTful/customer/12345?discountJSon: { "procedure" : "PUT.customer", "args" : [ 12345, "discount" ] }
URI: GET
http://my.server.org/RESTful/customer/12345/discountJSon: { "procedure" : "PUT.customer.12345", "args" : [ "discount" ] } (probably useless!)
URI: GET
http://my.server.org/RESTful/customer/discount/12345JSon: { "procedure" : "PUT.customer.discount", "args" : [ "12345" ] } (better semantic)
URI: GET
http://my.server.org/RESTful/customer/discount/#{my:[horribly, complex, {json:string}, {badly:terminatedJSon: { "procedure" : "PUT.customer.discount", "args" : [ "my" : { "horribly", "complex", { "json" : "string" }, { "badly" : "terminated" } ] } (... if I didn't make any stupid typos ;) )
This scheme (or something similar) allows to encode arbitrary JSon fragments and the real limit is how much we want to make complex the URI.
I do expect people to encode this way simple things and to fall back to currently available schemes (i.e.: direct JSon encoding) when the URI becomes too cumbersome.
Did I forget something?
Do You thing this is feasible?
If so: what is the best implementation path?
Thanks
Mauro