You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			38 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Markdown
		
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Markdown
		
	
### Build plugins
 | 
						|
A plugin is a basic <b>python</b> function that takes positional arguments i.e one being <b>request</b> and the other <b>config</b>. We allow the function to have access to the request object (if data were submitted) and to QCMS configuration if any configuration data is needed.
 | 
						|
 | 
						|
    
 | 
						|
    <div class="source-code editor border">
 | 
						|
        <span class="code-comment"># saving this function to www/html/_plugins/myplugins.py</span>
 | 
						|
        <span class="code-comment">#</span>
 | 
						|
        <span class="keyword">import</span> numpy as np
 | 
						|
        <span class="keyword">import</span> cms 
 | 
						|
 | 
						|
        @cms.Plugin(mimetype="application/json", methods=["POST"])
 | 
						|
        <span class="keyword">def</span> demo(**_args):
 | 
						|
            req = _args['request']
 | 
						|
            conf= _args['config']
 | 
						|
            <span class="keyword">return</span> {"name":"foo","age":np.random.randint(0,100)}
 | 
						|
    </div>
 | 
						|
 | 
						|
### Register Plugin
 | 
						|
 | 
						|
Once a plugin is build it needs to be registered, in order to allow the function be made available to calling code (JS/HTML5) 
 | 
						|
 | 
						|
<div class="source-code">
 | 
						|
$ qcms plugin-register qcms-manifest.json myplugins.py --import demo
 | 
						|
</div>
 | 
						|
 | 
						|
Calling the registered function as an API. The example uses <b>curl</ba>
 | 
						|
<div class="source-code">
 | 
						|
$ curl http://localhost:8000/api/myplugins/demo
 | 
						|
</div>
 | 
						|
 | 
						|
### Limitations
 | 
						|
 | 
						|
**QCMS** lowers the barrier to entry and makes the following tradeoffs to deliver an optimal solution:
 | 
						|
<ul>
 | 
						|
    <i class="fa-solid fa-minus"></i> Plugins are basic python function that need to be registered with <b>QCMS</b> instance/site
 | 
						|
    <br><i class="fa-solid fa-minus"></i> We delegate access control (read/write) to web content to a cloud service provider (nextcloud for now).
 | 
						|
</ul>
 |