bgrabitmap / lazpaint

🎨 Cross-platform image editor with raster and vector layers similar to Paint.Net written in Lazarus (Free Pascal)
https://lazpaint.github.io/
GNU General Public License v3.0
401 stars 55 forks source link

Implement HTTP API for Plugin Communication #569

Open circular17 opened 11 months ago

circular17 commented 11 months ago

We've been exploring options for more flexible and scalable plugin integrations. Based on the discussions and a demo shared by @lainz in https://github.com/bgrabitmap/lazpaint/issues/553#issuecomment-1752176751, we're leaning towards implementing an HTTP API to facilitate communication between LazPaint and various plugins.

Currently scripts have their own Script menu. For starters, we can use this menu to access plugins, but maybe we could rename it at some point.

The plugin invocation via the menu would have the following steps:

One thing to consider is how to close the plugin if it never notifies via the API that it finishes. Same applies in fact to Python scripts, though in this case, one can close or kill Python task. This is not possible with a waiting API. Another approach is to require the plugin to notify it is still open every 10 seconds.

The API would provide, on top of the specific functions related to web plugin invocation, the usual scripting functions, the path of the URL being /api/ followed by the name of the function and the parameters provided via POST object parameter in JSON. The token would be an additional parameters. The case of the variables may change to make it more web-like ("spinal-case" case instead of Pascal case for function names and parameters).

The scripting results would be mapped to http codes as following:

Additionally the URL / or /index.html could return a page saying the server is running and list the available functions.

lainz commented 10 months ago

Maybe a Json file can be used to retrieve plugin information. Name (for each language), author, version, website, email...

circular17 commented 10 months ago

Yes, that could be a file next to the webpage.