Package: crossbarhttp3
Module that provides methods for accessing Crossbar.io HTTP Bridge ServicesFork of the original package byEric Chapman at The HQ, now supporting
Python 2.6, 2.7 and 3+ versions.InstallationInstall Crossbar HTTP 3 with pip:pip install crossbarhttp3Basic usageCallTo call a Crossbar HTTP bridge, do the following:client=Client('http://127.0.0.1/call')result=client.call('com.example.add',2,3,offset=10)This will call the followingadd_somethingmethod of anApplicationSession object:fromautobahn.twisted.wampimportApplicationSessionfromtwisted.internet.deferimportinlineCallbacksclassMyComponent(ApplicationSession):@inlineCallbacksdefonJoin(self,details):defadd_something(x,y,offset=0):print('Add was called')returnx+y+offsetyieldself.register(add_something,'com.example.add')PublishTo publish to a Crossbar HTTP bridge, do the following:client=Client('http://127.0.0.1/publish')result=client.publish('com.example.event',event='new event')The receiving subscription implemented in anApplicationSessionclass would
look like this:fromautobahn.twisted.wampimportApplicationSessionfromtwisted.internet.deferimportinlineCallbacksclassMyComponent(ApplicationSession):@inlineCallbacksdefonJoin(self,details):defsubscribe_something(event=None,**kwargs):print('Publish was called with event%s'%event)yieldself.subscribe(subscribe_something,'com.example.event')Key/SecretFor bridge services that have a key and secret defined, simply include the key
and secret in the instantiation of the client.client=Client('http://127.0.0.1/publish',key='key',secret='secret')Additional optionsThere are two more options available in the client instantiation:timeout: Lets you specify a number of seconds from which an idle request to the Crossbar.io node will be dismissed (timed out). Defaults toNone, meaning that the global default timeout setting will be used.silently: If set toTrue, any failed request to the Crossbar.io node will be returned by the client asNone,without raising any exception. Defaults toFalse, meaning that all failures will raise their correspondent exceptions.ExceptionsThe library will throw the following exceptions.  Note that all exceptions
subclass fromClientBaseExceptionso you can just catch that if you don’t
want the granularity.ClientBadUrl- The specified URL is not a HTTP bridge serviceClientBadHost- The specified host name is rejecting the connectionClientMissingParams- The call was missing parametersClientSignatureError- The signature did not matchClientNoCalleeRegistered- Callee was not registered on the router for the specified procedureClientCallRuntimeError- Procedure triggered an exceptionContributingAll bug-fixes or improvements to the library are welcome.To contribute, fork the repo and submit a pull request to thedevelopbranch. Please, try to follow this basic coding rules:Always include some unit tests for the new code you write or the bugs you fix. Or, update the existent unit tests if necessary.Stick toPEP-8styling.TestingIn order to test Crossbar HTTP 3 properly you must have a Crossbar.io node in
HTTP Bridge mode running in localhost port 8001. You can do that by yourself if
you need it, but otherwise there is aDocker imagealready prepared, so you
don’t have to bother with this.To use that image and raise a Docker container with everything working, make
sure you haveDocker installedand execute this command:docker run -t -p 8001:8001 --name crossbar-bridge joselpa/crossbar-http-bridge:0.2Then you can run the unit tests in the regular way:python setup.py testLicenseReleased underMIT License.