| Description: |
With how ::rest works now, you can define a single callback for a route. The only ways to get a different callback then configured in the ::rest::create step is to recreate the entire interface! Example:
=====================================================================
proc callback {method code response} {
...
}
set test(issue) [list\
method get\
url "http://basicUrl.com/routes/"\
auth basic\
content-type "application-type"\
callback callback\
result json]
::rest::create_interface test
after 5000 {set done 1}
::test::issue ;# Same callback
::test::issue ;# Same callback again
::test::issue ;# Same callback again
vwait done
=====================================================================
All three ::test::issue calls above will call the same callback- It would be great if we could have some way to dynamically control that like we can with URL arguments! We've gotten around this lack of functionality like so:
=====================================================================
# Assoc. array to store callbacks
array set callbackHandler [list]
proc callbackDispatcher {method code {response ""}} {
upvar token token
set mySock $token(sock)
puts "I should call: ::callbackHandler($mySock) == $::callbackHandler($mySock)"
{*}$::callbackHandler($mySock) $method $code $response
unset ::callbackHandler($mySock)
}
proc otherCallback {method code {response "-"}} {
puts "othercallback"
puts "\tArg Method: --$method--"
puts "\tArg Code: --$code--"
}
proc otherCallback_2 {name method code {response "-"}} {
upvar token token
puts "otherCallback_2"
puts "\tArg Name: --$name--"
puts "\tArg Method: --$method--"
puts "\tArg Code: --$code--"
}
set test(issue) [list\
method get\
url "http://basicUrl.com/routes/"\
auth basic\
content-type "application-type"\
callback callbackDispatcher\
result json]
::rest::create_interface test
after 5000 {set done 1}
set myTok [::test::issue]
upvar 0 $myTok httpToken
set callbackHandler($httpToken(sock)) otherCallback
set myTok2 [::test::issue]
upvar 0 $myTok2 httpToken2
set callbackHandler($httpToken2(sock)) [list otherCallback_2 "otherVar"]
vwait done
=====================================================================
Which allows us dynamic callbacks! Its a little strange to rely on the http sock as our unique identifier but there is nothing else unique in the http token array.
If we could instead do something like
=====================================================================
::test::issue -callback otherCallback
::test::issue -callback [list otherCallback_2 "otherVar"]
=====================================================================
in addition to the URL arguments that would be awesome! If that's not possible, getting a unique identifier in the http token that isn't a socket handle would be nice as well :)
|