From 148eeccaf3b31d4403717f88e9a1a2b03a060682 Mon Sep 17 00:00:00 2001 From: Manuel83 Date: Mon, 3 Jul 2017 07:07:17 +0200 Subject: [PATCH] Created Custom Web Endpoint (markdown) --- Custom-Web-Endpoint.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Custom-Web-Endpoint.md diff --git a/Custom-Web-Endpoint.md b/Custom-Web-Endpoint.md new file mode 100644 index 0000000..30f9f2d --- /dev/null +++ b/Custom-Web-Endpoint.md @@ -0,0 +1,32 @@ +Adding a new HTTP Endpoint is also possible. + +In the following example the endpoint will be available under: + +`http://:5000/api/myendpoint/` + +The endpoint name must be unique in the entire system. + +See [Flask BluePrint](http://flask.pocoo.org/docs/0.12/blueprints/) for more information + +``` +# -*- coding: utf-8 -*- +import os +from subprocess import Popen, PIPE, call + +from modules import cbpi +import json +from flask import Blueprint, render_template, jsonify, request + +blueprint = Blueprint('http_sensor1', __name__) + + +@blueprint.route('/', methods=['GET']) +def hello_world(): + + return "HELLO WORLD" + +@cbpi.initalizer() +def init(cbpi): + cbpi.app.register_blueprint(blueprint, url_prefix='/api/myendpoint') + print "READY" +``` \ No newline at end of file