uhd-urz / elAPI

An extensible API client for eLabFTW
GNU Affero General Public License v3.0
5 stars 0 forks source link

Add support for additional HTTP parameters (--verify, --timeout, --headers) - [merged] #99

Closed alexander-haller closed 1 month ago

alexander-haller commented 1 month ago

In GitLab by @mhxion on Jun 13, 2024, 15:43

Merges additional-http-client-parameters -> dev

This PR essentially adds three new arguments that can be passed to either of get, post, patch, delete commands: --verify, --timeout, --headers. This also completes one feature request from FDM workshop #20, and partially fixes #39.

New CLI arguments to raw API commands

Mainly copypasta from elapi get --help.

--verify: SSL certificates are verified for HTTPS requests by default. Passing --verify False will disable the verification. This can be useful during local development. You can also pass a path to SSL certificate (a.k.a CA bundle) file to --verify.

$ elapi get info --verify False
<Successful response>
$ elapi get info --verify ~/ca-bundle.crt
<Successful response>

--timeout: Maximum number of seconds elAPI will wait for response before giving up. Default timeout is 5 seconds.

$ elapi get info --timeout 10
<Successful response>

--headers: elapi decides the appropriate headers in most cases. --headers will let you overwrite the default headers sent. The value for --headers should be in JSON format.

$ elapi get info --headers '{"Accept": "application/json", "User-Agent": "My custom agent 1.0"}'
<Successful response>

Note: If one is using --headers, passing a bad header can result in a bad response. Though this is not mentioned in the CLI --help.


As part of the same change, elAPI's HTTP APIs will now support passing any arbitrary argument that HTTPX has support for its get, post, patch and delete.

from elapi.apis import GETRequest

session = GETRequest(timeout=10, follow_redirects=True)
print(session("experiments").json())
alexander-haller commented 1 month ago

In GitLab by @mhxion on Jun 13, 2024, 15:43

requested review from @alexander-haller

alexander-haller commented 1 month ago

In GitLab by @project_994_bot_1c5bd6ac1fdbd740fbc4ed080ecff58d on Jun 13, 2024, 16:56

added 1 commit

Compare with previous version

alexander-haller commented 1 month ago

In GitLab by @project_994_bot_1c5bd6ac1fdbd740fbc4ed080ecff58d on Jun 13, 2024, 17:06

added 1 commit

Compare with previous version

alexander-haller commented 1 month ago

approved this merge request

alexander-haller commented 1 month ago

In GitLab by @project_994_bot_1c5bd6ac1fdbd740fbc4ed080ecff58d on Jun 13, 2024, 21:22

added 1 commit

Compare with previous version

alexander-haller commented 1 month ago

In GitLab by @mhxion on Jun 13, 2024, 21:26

Commit fd19b564 enables HTTP/2.