[!WARNING]
Currently based on #440. Once that is merged, we'll make a new branch, feature-http-api, that will be based on the then updated dev branch and target feature-http-api with this PR. So don't merge just quite yet :slightly_smiling_face:
This PR introduces a first version of an HTTP API to execute looper commands (#433).
Changes made:
Implemented a new HTTP API using FastAPI to run the looper run command.
Slightly modified the enrich_vars_cfg() function in looper/utils.py module to enable execution via both the CLI and the HTTP API.
Slightly refactor cli_pydantic.py
Endpoints
/ (POST): allows users to trigger looper commands asynchronously . For now, because we only have the run command modeled as a pydantic model, only the run command is supported. Returns a unique job ID that can be used in the /status endpoint.
This endpoint accepts a JSON payload with the run model and other top-level parameters such as looper_config, see the auto-generated documentation on http://127.0.0.1:8000/docs and / or looper/command_models/commands.py.
/status/<job ID> (GET): retrieve the status / results of a previously started job. Returns a JSON with, notably, a field console_output that contains all stdout / stderr from the performed looper run, once the job has finished.
Usage:
Run the app:
looper-serve [--host <host IP address>] [--port <port>]
[!NOTE]
This assumes that all files specified in the arguments are available on the file system of the machine that is running the HTTP API server. Best make sure you use absolute file paths in all looper YAML configuration files.
To test this, you can clone the hello_looper repository and then run (for example) the following in a second terminal:
This PR introduces a first version of an HTTP API to execute
looper
commands (#433).Changes made:
looper run
command.enrich_vars_cfg()
function inlooper/utils.py
module to enable execution via both the CLI and the HTTP API.cli_pydantic.py
Endpoints
/
(POST
): allows users to triggerlooper
commands asynchronously . For now, because we only have therun
command modeled as apydantic
model, only therun
command is supported. Returns a unique job ID that can be used in the/status
endpoint. This endpoint accepts a JSON payload with therun
model and other top-level parameters such aslooper_config
, see the auto-generated documentation onhttp://127.0.0.1:8000/docs
and / orlooper/command_models/commands.py
./status/<job ID>
(GET
): retrieve the status / results of a previously started job. Returns a JSON with, notably, a fieldconsole_output
that contains allstdout
/stderr
from the performedlooper
run, once the job has finished.Usage:
Run the app:
To test this, you can clone the
hello_looper
repository and then run (for example) the following in a second terminal:This will return a six-letter job ID, say
abc123
. Then get the result / output of the run withFor better visualization / readability, you can post-process the output by piping it to
jq
(| jq -r .console_output
).