I am recently working with a project which requires to handle dynamic URI. Anyway, it requires two dynamic variables. The possible way to take these two variables are:
Both as path variables:
coap://:/explore/{VAR_1}/{VAR_2}
One of them as variable and other as query parameter in query string:
coap://:/explore/{VAR_1}?VAR_2=var_2
Both as query parameters in query string:
coap://:/explore?VAR_1=var_1&VAR_2=var_2
I am able to pass one of them path variable but I am not able to pass both neither in path variables nor in query string.
The following code can handle just one variable:
import sys
import datetime
from twisted.internet import defer
from twisted.internet import reactor
from twisted.python import log
import txthings.resource as resource
import txthings.coap as coap
class ExploreResource(resource.CoAPResource):
"""Can handle 1 dynamic path variable ()"""
def __init__(self, pathVar1):
resource.CoAPResource.__init__(self)
self.pathVar1 = pathVar1
def render_POST(self, request):
# todo with self.pathVar1
payload = "%s added successfully!" % self.pathVar1
response = coap.Message(code=coap.CONTENT, payload=payload)
return defer.succeed(response)
class ExploreDynamicResource(resource.CoAPResource):
def getChild(self, pathVar1, request):
return ExploreResource(pathVar1)
# start log to the console
log.startLogging(sys.stdout)
# coap://<host>:<port>
root = resource.CoAPResource()
explore_discovery = ExploreDynamicResource()
root.putChild('explore', explore_discovery)
endpoint = resource.Endpoint(root)
reactor.listenUDP(coap.COAP_PORT, coap.Coap(endpoint)) # , interface="::")
reactor.run()
What I need to do in server code to get both VAR_1 and VAR_2? Any Idea? I appreciate your valuable comments & suggestions.
I am recently working with a project which requires to handle dynamic URI. Anyway, it requires two dynamic variables. The possible way to take these two variables are:
Both as path variables:
coap://:/explore/{VAR_1}/{VAR_2}
One of them as variable and other as query parameter in query string:
coap://:/explore/{VAR_1}?VAR_2=var_2
Both as query parameters in query string:
coap://:/explore?VAR_1=var_1&VAR_2=var_2
I am able to pass one of them path variable but I am not able to pass both neither in path variables nor in query string.
The following code can handle just one variable:
What I need to do in server code to get both VAR_1 and VAR_2? Any Idea? I appreciate your valuable comments & suggestions.
Thanks in advance!