01_user_documentation:10_additional_interfaces:api
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| 01_user_documentation:10_additional_interfaces:api [2025/01/30 10:54] – removed - external edit (Unknown date) 127.0.0.1 | 01_user_documentation:10_additional_interfaces:api [2025/12/10 13:14] (current) – ↷ Links adapted because of a move operation gaetan | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | [[https:// | ||
| + | |||
| + | ====== API ====== | ||
| + | |||
| + | GroIMP can be started as an HTTP API that provides a generalized set of commands allowing interaction from other software. Currently a Python and a R library are provided but any software capable of HTTP requests could interact with GroIMP. This approach can be used to automatically start a simulation and interact with it during the execution. | ||
| + | |||
| + | |||
| + | <uml> | ||
| + | @startuml | ||
| + | !pragma teoz true | ||
| + | hide footbox | ||
| + | title API | ||
| + | |||
| + | participant User | ||
| + | participant ClientScript | ||
| + | participant API | ||
| + | participant GroIMP | ||
| + | |||
| + | |||
| + | User -> GroIMP: Start GroIMP | ||
| + | User -> ClientScript | ||
| + | ClientScript < | ||
| + | & API< | ||
| + | User <- ClientScript | ||
| + | User -> GroIMP: Stop GroIMP | ||
| + | |||
| + | |||
| + | @enduml | ||
| + | </ | ||
| + | ===== Installation and execution ===== | ||
| + | |||
| + | Starting with GroIMP 2.1 the API application is included and can be started with the following command: | ||
| + | |||
| + | > java -Xverify: | ||
| + | |||
| + | This starts a local web server, the default port is 58081, this can be changed either in the preferences panel in the GUI or by adding '' | ||
| + | A more in-depth explanation of GroIMP arguments can be found [[01_user_documentation: | ||
| + | |||
| + | Now the API can be reached at [[http:// | ||
| + | |||
| + | |||
| + | ===== HTTP request structure ===== | ||
| + | |||
| + | Every command acepted by the API server follows the schema below: | ||
| + | |||
| + | > %%< | ||
| + | |||
| + | * **host**: The IP of the server (or localhost) | ||
| + | * **port**: Where the API is listening | ||
| + | * **ref**: The reference to the workbench (‘app’ or ‘wb/< | ||
| + | * **command**: | ||
| + | * **key**: Name of a parameter | ||
| + | * **value**: Of the parameter | ||
| + | |||
| + | Depending on the command there can be several key value pairs as well as a request body containing decode file. The list of all available commands can be found [[ https:// | ||
| + | |||
| + | The GroLink API does not distinguish between different request methods. | ||
| + | |||
| + | ===== Project management ===== | ||
| + | |||
| + | The GroLink API can be used to manage multiple files and is started without a specific project. To do so a main workbench is used which can be addressed using the reference (ref) " | ||
| + | This main workbench can create new workbenches, | ||
| + | The main workbench is also able to list all currently opened workbenches. | ||
| + | |||
| + | In any cases it returns a workbench id that can then be used to address the new workbench with the ref wb/< | ||
| + | A request send to the sever will be forwarded directly to the referenced workbench, where it is either executed or if the workbench is busy wait. After the completion of the command from the request the request response to the client. In this way the API server has never to wait for any execution to be completed and can run non blocking. | ||
| + | |||
| + | ==== Opening a Project ==== | ||
| + | |||
| + | There are two different ways to open a project, | ||
| + | |||
| + | After transferring the file both commands work similarly, they open a workbench the same way as in the GUI or the CLI and then return a workbench ID. | ||
| + | ([[https:// | ||
| + | |||
| + | ==== Creating a workbench ==== | ||
| + | |||
| + | [[https:// | ||
| + | By default the new workbench will be using the new RGG template, yet it is possible to provide the name of another template that should be used. The templates can be listed with a [[https:// | ||
| + | |||
| + | |||
| + | ==== Loading an example ==== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | |||
| + | ==== Saving a project ==== | ||
| + | |||
| + | Saving the project is a workbench command that has to be addressed to the workbench that is suppose to be saved. If a path is provided the project will be saved at that location, otherwise if no path is provided the decoded gsz file will be returned to the client. This allows to save project that where executed on other file systems. | ||
| + | ([[https:// | ||
| + | |||
| + | ===== Project interaction ===== | ||
| + | |||
| + | |||
| + | ==== RGG/ XL ==== | ||
| + | |||
| + | It is possible to send the name of an RGG function to the project and receive the output of the XL console as a result ([[https:// | ||
| + | |||
| + | In a similar fashion it is possible to [[https:// | ||
| + | While it is possible to send the XL query as an URL parameter, for more complex queries it would be recommended to use the request body since several characters of the XL syntax are effecting urls. | ||
| + | |||
| + | ==== Graph view ==== | ||
| + | |||
| + | The API can [[https:// | ||
| + | |||
| + | The JSON format uses two dictionaries to represent the graph: " | ||
| + | The projectgraphNodes list holds the nodes themselves with their node id. This ID is again used in | ||
| + | triples of the projectgraphEdges list to define the source (first entry) and the destination (second entry). The third value in the triple represents the edge bits to seperate for example successor and branch. Finally the projectgraphRoot represents the root node of the project graph. | ||
| + | |||
| + | |||
| + | ==== File management ==== | ||
| + | |||
| + | The source files of a project can be [[https:// | ||
| + | |||
| + | Adding a file can be done via a path or as a request body, similar to opening a project. | ||
| + | Updating a file will replace the content of the given file with the body of the request, meaning to change only one line it would be reasonable to first read the file, change it locally and then send it back. | ||
| + | |||
| + | |||
| + | ==== Import/ | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | ==== Data handling ==== | ||
| + | |||
| + | While data handling through external files for instance for logging, is still possible, this would not be that suitable for a setup where the API server and the client are not running on the same system. | ||
| + | In that case a possible way is to just add input data files as source files to the project and read them from RGG. | ||
| + | |||
| + | To receive data from the simulation one possible way is to use datasets, the API has specific commands to [[https:// | ||
| + | |||
| + | |||
| + | ===== Client libraries ===== | ||
| + | |||
| + | Due to the generalized approach using registry paths, the HTTP commands are quite long and complex. | ||
| + | To ease this and the management of the workbenches, | ||
| + | ==== GroPy ==== | ||
| + | |||
| + | The [[https:// | ||
| + | <code bash> | ||
| + | pip install GroPy --index-url https:// | ||
| + | </ | ||
| + | Additionally it is possible to only get the file GroPy.py from the repository and link it directly. | ||
| + | |||
| + | === Structure === | ||
| + | |||
| + | The library is based on three classes: Call, GroLink and WBRef. | ||
| + | |||
| + | == Call == | ||
| + | |||
| + | A call object represents a possible request to the API server and can be send with the run function and the results can be interpreted with the read function. The run function returns the object itself to enable a short writing form: '' | ||
| + | |||
| + | == GroLink == | ||
| + | |||
| + | The GroLink class holds the connection to the API server and can create different calls for [[# | ||
| + | |||
| + | |||
| + | == WBRef == | ||
| + | |||
| + | A WBRef object represents the connection to a workbench, it does not hold any information other than the id of the workbench and the link to the API server. This object provides function to create calls for the [[# | ||
| + | |||
| + | === custom calls === | ||
| + | |||
| + | Due to the design of the API server it is possible to send request regarding commands that where not originally part of the GroLink project. To be able to address this command from the python library the function '' | ||
| + | <code python> | ||
| + | link = GroPy.GroLink(" | ||
| + | link.createAppCall("/ | ||
| + | WBref1 = link.createWB().run().read() | ||
| + | WBref1.createWBCall("/ | ||
| + | </ | ||
| + | |||
| + | ==== GroR ==== | ||
| + | [[https:// | ||
| + | |||
| + | === Installation === | ||
| + | |||
| + | The GroR package is not added to any public repository and must therefore be installed by hand. This can be done in different ways depending on your needs. | ||
| + | |||
| + | == Adding the R file as a Source == | ||
| + | |||
| + | It is possible to download the GroR.R file from this repository and link it to your R file with this code: | ||
| + | '' | ||
| + | |||
| + | == Package == | ||
| + | |||
| + | The releases contain packages that can be installed directly with either the R command: | ||
| + | |||
| + | '' | ||
| + | |||
| + | Alternatively, | ||
| + | |||
| + | === Structure === | ||
| + | |||
| + | The library comes with two sets for functions, one set with the prefix " | ||
| + | |||
| + | |||
| + | ===== More documentation ===== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[01_user_documentation: | ||
| + | |||
| + | ===== Tutorials ===== | ||
| + | |||
| + | * [[02_user_tutorials: | ||
| + | * [[02_user_tutorials: | ||
| + | * [[02_user_tutorials: | ||
| + | * [[02_user_tutorials: | ||
| + | * [[02_user_tutorials: | ||
| + | * [[05_developer_tutorials: | ||
| + | |||
| + | ===== Examples ===== | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
