Git Product home page Git Product logo

mqtt-rest-bridge's Introduction

MQTT REST Bridge

MQTT REST Bridge is a package to bridge between MQTT and REST protocols. We call APIs make multiple Python projects connected with it.

How to install

poetry add git+https://github.com/NubeIO/mqtt-rest-bridge@master

How to delete

poetry remove mqtt-rest-bridge

How to integrate

from mrb.brige import MqttRestBridge
from mrb.setting import MqttSetting

def callback():
    print('callback...')

MqttRestBridge(port=8080, mqtt_setting=MqttSetting(), callback=callback)

Request examples

Example to GET value from slave:

from mrb.mapper import api_to_slave_topic_mapper
from mrb.message import Response, HttpMethod

response: Response = api_to_slave_topic_mapper(slave_global_uuid=f'<uuid>',
                                               api=f'/api/generic/networks',
                                               http_method=HttpMethod.GET)

Example to POST value to slave:

import json
from mrb.mapper import api_to_slave_topic_mapper
from mrb.message import Response, HttpMethod

body: json = {
    "name": "generic_network",
    "enable": True,
    "history_enable": True
}
response: Response = api_to_slave_topic_mapper(slave_global_uuid=f'<uuid>',
                                               api=f"/api/generic/networks",
                                               body=body,
                                               headers={},
                                               http_method=HttpMethod.POST)

Example to DELETE value on slave:

from mrb.mapper import api_to_slave_topic_mapper
from mrb.message import Response, HttpMethod

response: Response = api_to_slave_topic_mapper(slave_global_uuid=f'<uuid>',
                                               api=f'/api/generic/networks/b7a23aa5-b8a1-4a0f-9acf-4fb011bce50e',
                                               http_method=HttpMethod.DELETE)

Example to GET value from master:

from mrb.mapper import api_to_master_topic_mapper
from mrb.message import Response, HttpMethod

response: Response = api_to_master_topic_mapper(api=f'/api/generic/networks',
                                                http_method=HttpMethod.GET)

Example to GET values on master from slaves:

from mrb.mapper import api_to_slaves_broadcast_topic_mapper
from mrb.message import Response, HttpMethod

response: Response = api_to_slaves_broadcast_topic_mapper(api=f'/api/system/ping',
                                                http_method=HttpMethod.GET)

How to differentiate REST vs MQTT > REST requests

is_bridge(request.args)  # True if MQTT > REST, else REST

mqtt-rest-bridge's People

Contributors

raibnod avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.