Develop the first plug -in#
Create a plug -in directory and file#
cloneUnder ARKID's git warehouse,Find in the root directory arkid.toml document turn up extension item,The file location of the configuration indicator plugin,as follows:
exist my_extensions New folder in the directory,named:com_company_type_helloworld
Notice
The file name of the plug -in directory should completely correspond to its Package,Just put the symbol point of Package '.' Change to the bottom line'_'
In a folder com_company_type_helloworld Down,create a new file__init__.py
In this way, the main directory of the plugin and the main file are completed。
Write plug -in code (parsing by line by line)#
exist __init__.py Insert the following code in the file:
- ArkIDThe kernel code is in Arkid.Core in this package, extension (various base classes related to plugins), API (encapsulated ninja API object), Event (all objects and methods related to the event)
- Event tag
- Package of the plug -in, Because of repeatedly,Should be defined alone
- Define plug -in,Inherit the most basic plug -in base class Extension
- load() Abstract method,The core startup method of all plug -in,Must be realized
- Registration event in the plug -in,In order to make the TAG naming conflict,Will add in front of the passing tag package+'.' Prefix
- Add the callback function of the listening event
- Define the callback function
- Print the data parameter of Event
- Define a API,Reference django-Ninja related documents
- Define the SCHEMA of the API,In order to avoid naming conflicts,Can only be via extension.create_extension_schema method
- Throw an incident,Note that the tag of the event is to add the prefix part
- Single object that generates the plugin,Arkid will get__init__.The extension object in the py file as the main body of the plugin
Load and start plug -in#
Start django
ArkIDWill according to Arkid.Configuration in TOML file,Automatically load all plug -in in turn in all plug -in directory,And print out loading information。Importing my_extension/com_company_type_helloworld
xxxx-xx-xx 03:21:57,944 - arkid - INFO - Imported <module 'my_extension.com_company_type_helloworld' from '/arkid/my_extension/com_company_type_helloworld/__init__.py'>
xxxx-xx-xx 03:21:57,944 - arkid - INFO - my_extension.com_company_type_helloworld import success
Check and test plug -in#
access:
http://{ArkID host}/api/redoc#tag/helloworld/operation/my_extension_com_company_type_helloworld_helloworld
You can see that the API defined in the plug -in will be displayed in the documentation, Try to call the interface,Can get printing:
Hint
Interface tenant_id allowable Tenant management-Practice configuration See