Skip to main content

Hermes cURL is a lightweight wrapper on top of cURL that provides reusable HTTP request configurations in YAML.

Project description

Hermes cURL

Hermes cURL is a lightweight wrapper on top of cURL that provides reusable HTTP request configurations in YAML. Configuration files can import attributes from other files which allows for common settings such as hostnames and authentication headers to be shared by multiple cURL calls.

Usage

Set up a base configuration for an entire API:

# api_base.yml
headers:
  Authorization: Token MySecretAPIToken
  Content-Type: application/json
host: localhost:5000
curl_flags:
   "--location":

Set up a configuration for a specific endpoint and import our the base settings:

# api.yml
from: api_base.yml
method: PUT
path: /my/api
body: >
  {"hello": "world"}

Run the hermes command:

$ hermes api.yml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   128  100   112  100    16   3960    565 --:--:-- --:--:-- --:--:--  4000
{
   "msg": "hello Mr world"
}

See examples for a working example.

Installation

python3 -m pip install hermes-curl

Configuration file reference

Options

  • from (optional): specify a path to another configuration file to inherit configurations from. This path is relative to the current file.
  • path (requires): path on the server to send the request to, including any query params.
  • method (required): HTTP method to use.
  • host (required): server host, including protocol and port.
  • headers (optional): dictionary of headers in the form. ExHeader: value.
  • body (optional): request body.
  • curl_flags (optional): a dictionary with any other curl flags to add. Ex "--cacert: certfile".
  • template_defaults (optional): a dictionary of default template variables.

Config Inheritance

Configurations are merged in the following fashion:

  • Dictionaries are merged. Values set in child configs having precedence and override any values from the parent configuration.
  • path is concatenated, so setting path: /foo/ in the parent and path: /bar/ in the child will result in path: /foo/bar/
  • All other top level configurations use whatever value is set in the child configuration. This includes method, body, and host.

Template Variables

Configurations can contain variables using the {variable_name} syntax. Variables can be passed into the configuration by either setting -t variable_name=value on the cli or by setting template_defaults in the configuration. Values passed on the cli have precedence over values set in template_defaults.

Example

Running hermes -t pk=2 example.yml will GET http://localhost/api/thing/2/ and running hermes example.yml will GET http://localhost/api/thing/1/

host: http://localhost/
path: api/thing/{pk}/
method: GET
template_defaults:
  pk: 1

Example

Template variables can also be used via environment variables. This will inject the TOKEN environment variable into the Token header.

headers:
  Content-Type: application/json
  Authorization: "Token {env[TOKEN]}"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hermes_curl-1.0.7.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

hermes_curl-1.0.7-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file hermes_curl-1.0.7.tar.gz.

File metadata

  • Download URL: hermes_curl-1.0.7.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for hermes_curl-1.0.7.tar.gz
Algorithm Hash digest
SHA256 ca47b67c796be5b492fb24cdc091f9080373becce3b8a10334a3d144b282563c
MD5 4721a8aa014a95a0929c7f57d76e6b85
BLAKE2b-256 a33761045d6748f92f26c3969b894f85740de4ef7157bde5d8efacfb2742230d

See more details on using hashes here.

File details

Details for the file hermes_curl-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: hermes_curl-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for hermes_curl-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 58cddaa3811b75038510cdb3c1add7e1c514caa3598705e891c780cf1ff91ff1
MD5 3c5ce904cee059a10ea898f153bee1bf
BLAKE2b-256 31f48ea702aff818be2d9eaa3d1d5da90218e48eca3447b945f12b15fe6db714

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page