cli icon indicating copy to clipboard operation
cli copied to clipboard

per-directory config file (.httpierc)

Open kykungz opened this issue 4 years ago • 0 comments

Checklist

  • [x] I've searched for similar feature requests.

Enhancement request

It would be great to have a per-directory httpie config file such as .httpierc (same naming convention with .prettierrc, .eslintrc or .npmrc).


Problem it solves

The httpie config seems to act as a "global" config on all http or https command, which sometimes polluted the request that we are trying to make.

For example, I don't want to add the same api-key header on every requests I make, and by adding this header, some API calls might fail because they don't accept this same header.

The .httpierc idea seemed to be opened before at https://github.com/httpie/httpie/issues/953 but was closed in favor of the global ~/.config/httpie/config.json config file. However, the per-directory use case was not yet been solved.

This per-directory config file could also (indirectly) solve the problem of Config by host #809 too, but the reason that I want to go for directory-based config file is because it will not pollute localhost calls. For example, if I have multiple projects that are using http://localhost:5000, I won't have a way to distinguish them if I use the "Config by host" option.

I understand that we can use the HTTPIE_CONFIG_DIR to change the config directory to the local one, but having to explicitly set an env variable on every shell opened seems to be cumbersome and not friendly when working in teams.


Additional information, screenshots, or code examples

I think this could be achievable by adding a new step at get_default_config_dir to look for .httpierc on the current working directory (or by recursively looking for .httpierc on any top-level directory).

https://github.com/httpie/httpie/blob/df58ec683e4f574507ea944d95ed1749941aee95/httpie/config.py#L34-L45

kykungz avatar Dec 06 '21 10:12 kykungz