Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brettbuddin/curlenv

Template for managing prepared curl requests.
https://github.com/brettbuddin/curlenv

curl direnv

Last synced: 4 days ago
JSON representation

Template for managing prepared curl requests.

Awesome Lists containing this project

README

        

# curlenv

**curlenv** set of conventions for managing prepared HTTP requests via [curl](https://curl.se).
Environments are just collections of shell environment variables that are managed by [direnv](https://direnv.net).

It aims to be a simple command-line alternative to [Postman](https://www.postman.com) that directly leverages well known tools.

> [!IMPORTANT]
> **It's recommended you use curl v8.7.0 or greater.** curl v8.7.0 fixed a bug ([curl/curl@0f0edc2](https://github.com/curl/curl/commit/0f0edc283c340e8ddddc763b48d2f835b2270ab4)) where curl would not fail when it encountered a missing environment variable.

## Template

This a template repository and meant to be cloned as a starting point for your own project. In GitHub you can click the
`Use this template` button at the top of this page to get started.

Files within [env](env), [data](data), [request](request), and [workflow](workflow) directories are only examples and
can be deleted to be replaced by our own. They exist as a starting point for your own work.

---

## Directories and Files

| Name | Description |
| ---------------- | ----------------------------------- |
| [env/](env) | `*.env` and `*.envrc` files for [direnv](https://direnv.net). |
| [data/](data) | Static and templated data files. |
| [request/](request) | Requests defined by [curl configuration files](https://curl.se/docs/manpage.html#-K). |
| [workflow/](workflow) | Compositions using `data` and `request` files. |
| [.envrc](.envrc) | Entrypoint file for [direnv](https://direnv.net). |
| [required-variables.txt](required-variables.txt) | List of environment variables that are considered required for the project. All environments must set these variables. |
| .envrc.local | Uncommitted, local run commands sourced by [.envrc](.envrc) |
| .envrc.curlenv.* | Files generated by [`bin/curlenv-switch`](bin/curlenv-switch) using `*.env` and `*.envrc` files in [env/](env). These files are loaded by [.envrc](.envrc) by direnv. |

## Environments

Environments are managed by direnv and loaded with the `bin/curlenv-switch` command.

Both `*.env` and `*.envrc` environment files are supported. If all you need is a static environment variables then choose
the `*.env` variant, because `*.envrc` files sourced by `.envrc` aren't guarded by `direnv`'s security framework.

Refer to the [direnv documentation](https://direnv.net/man/direnv.1.html) for `.env` and `.envrc` syntax and [stdlib
functions](https://direnv.net/man/direnv-stdlib.1.html).

You can load environments via the [`bin/curlenv-switch`](bin/curlenv-switch) script. The command accepts a single argument for the environment name. References to both the primary environment files (`.env` and `.envrc`) and optional secrets files (`.secret.env` and `.secret.envrc`) are symlinked in the project root.

```
; curlenv-switch example
curlenv-switch: wrote /Users/brett/Code/curlenv/.env.curlenv
curlenv-switch: wrote /Users/brett/Code/curlenv/.env.curlenv.target
direnv: loading ~/Code/curlenv/.envrc
direnv: loading ~/Code/curlenv/.envrc.curlenv.target
direnv: export +CURLENV_CURRENT +EXAMPLE_HEADER +EXAMPLE_HOSTPORT +EXAMPLE_SCHEME +EXAMPLE_USER -PS2 ~PATH
```

When a target environment is loaded, environment variable names (one per line) from `required-variables.txt` are applied to a
[`env_vars_required`](https://direnv.net/man/direnv-stdlib.1.html#codeenvvarsrequired-ltvarnamegt-ltvarnamegt-code) directive.