Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does it interact with Flask-Restful? #11

Open
rasa911216x opened this issue Jul 9, 2021 · 0 comments
Open

How does it interact with Flask-Restful? #11

rasa911216x opened this issue Jul 9, 2021 · 0 comments

Comments

@rasa911216x
Copy link

Hi! I decided to build an application using the Flask-Pluginengine architecture. I'm trying to create it as a RESTful service that feeds an Angular frontend. To build it I use the Flask Restful extension library to organize the code.

Currently I'm using this hacky version of my code to work with Plugins, but I'd like to know if there's a more proper way to integrate Flask-Restful and Flask-PluginEngine. Thanks for this amazing work!

App structure:

MainApp.py
plugins
-----test
---------setup.py
---------TestPlug.py

MainApp.py

#Import Flask library and dependencies.
from flask import Flask
#Import Flask Restful.
from flask_restful import Resource, Api, reqparse

#Import library to allow Plugin modules.
from flask_pluginengine import PluginFlask, PluginEngine

#Define a new flask App.
app = PluginFlask(__name__)
#Transform the App into a Restful instance.
api = Api(app)

#Initialize Flask plugin.
app.config['PLUGINENGINE_NAMESPACE'] = 'plugins'
app.config['PLUGINENGINE_PLUGINS'] = ['testplug']
#Load the Plugins available.
plugin_engine = PluginEngine(app=app)
plugin_engine.load_plugins(app)
active_plugins = plugin_engine.get_active_plugins(app=app).values()
print(active_plugins)

PluginCode called TestPlug.py

from flask_pluginengine import Plugin
from flask_app import Resource, api

class TestPlugin(Plugin):
    def get(self):
        print("It works!!!")

class TestPluginCode(Resource):
    def get(self):
        return "It works!!!"

api.add_resource(TestPluginCode, "/testplug")

Setup file for the plugin called setup.py

from setuptools import setup

setup(
        name='testPlugin',
        version='0.0.1',
        #Module that you'll be using.
        py_modules=['testplug'],
        entry_points={'plugins': {'testplug=TestPlug:TestPlugin'}}
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant