| 1 | # netrc |
| 2 | |
| 3 | A [netrc](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html) |
| 4 | library for Rust, with support for [reqwest](https://crates.io/crates/reqwest) |
| 5 | via [reqwest-middleware](https://crates.io/crates/reqwest-middleware). |
| 6 | |
| 7 | |
| 8 | ## reqwest-netrc |
| 9 | |
| 10 | The `reqwest-netrc` crate is a middleware for [reqwest](https://crates.io/crates/reqwest) |
| 11 | to support the `netrc` file. |
| 12 | |
| 13 | [![crates.io][crates-badge-2]][crate-url-2] |
| 14 | [![Documentation][doc-badge-2]][doc-url-2] |
| 15 | [![MIT licensed][mit-badge]][mit-url] |
| 16 | [![CI][actions-badge-2]][actions-url-2] |
| 17 | |
| 18 | |
| 19 | ### Usage |
| 20 | |
| 21 | To bring this crate into your repository, either add `reqwest-netrc` to your |
| 22 | `Cargo.toml`, or run: |
| 23 | |
| 24 | ``` |
| 25 | > cargo add reqwest-netrc |
| 26 | ``` |
| 27 | |
| 28 | ### Example |
| 29 | |
| 30 | The common scenario is to have a `~/.netrc` file or the `NETRC` environement variable defined: |
| 31 | |
| 32 | ```rust |
| 33 | use reqwest::Client; |
| 34 | use reqwest_middleware::ClientBuilder; |
| 35 | use reqwest_netrc::NetrcMiddleware; |
| 36 | |
| 37 | // ... |
| 38 | |
| 39 | let client = ClientBuilder::new(Client::builder().build().unwrap()) |
| 40 | .with_init(NetrcMiddleware::new().unwrap()) |
| 41 | .build(); |
| 42 | |
| 43 | let res = client.get("https://domain.io/api/hello").send().await; |
| 44 | |
| 45 | // ... |
| 46 | ``` |
| 47 | |
| 48 | ## rust-netrc |
| 49 | |
| 50 | The `rust-netrc` crate is a parser for the `netrc` files. |
| 51 | |
| 52 | [![crates.io][crates-badge]][crate-url] |
| 53 | [![Documentation][doc-badge]][doc-url] |
| 54 | [![MIT licensed][mit-badge]][mit-url] |
| 55 | [![CI][actions-badge]][actions-url] |
| 56 | |
| 57 | ### Usage |
| 58 | |
| 59 | To bring this crate into your repository, either add `rust-netrc` to your |
| 60 | `Cargo.toml`, or run: |
| 61 | |
| 62 | ``` |
| 63 | > cargo add rust-netrc |
| 64 | ``` |
| 65 | |
| 66 | ### Example |
| 67 | |
| 68 | ```rust |
| 69 | use netrc::Netrc; |
| 70 | |
| 71 | fn main() { |
| 72 | let nrc = Netrc::new().unwrap(); |
| 73 | |
| 74 | for (host, auth) in nrc.hosts { |
| 75 | println!("{host}: {auth:?}"); |
| 76 | } |
| 77 | } |
| 78 | ``` |
| 79 | |
| 80 | |
| 81 | ## Contributing |
| 82 | |
| 83 | Feedback and contributions are very welcome. |
| 84 | |
| 85 | |
| 86 | ## License |
| 87 | |
| 88 | This project is licensed under [MIT](./LICENSE). |
| 89 | |
| 90 | |
| 91 | [mit-badge]: https://img.shields.io/crates/l/rust-netrc.svg |
| 92 | [mit-url]: ./LICENSE |
| 93 | |
| 94 | [crates-badge]: https://img.shields.io/crates/v/rust-netrc.svg |
| 95 | [crate-url]: https://crates.io/crates/rust-netrc |
| 96 | [doc-badge]: https://docs.rs/rust-netrc/badge.svg |
| 97 | [doc-url]: https://docs.rs/rust-netrc |
| 98 | [actions-badge]: https://github.com/gribouille/netrc/actions/workflows/rust-netrc.yml/badge.svg |
| 99 | [actions-url]: https://github.com/gribouille/netrc/actions/workflows/rust-netrc.yml |
| 100 | |
| 101 | [crates-badge-2]: https://img.shields.io/crates/v/reqwest-netrc.svg |
| 102 | [crate-url-2]: https://crates.io/crates/reqwest-netrc |
| 103 | [doc-badge-2]: https://docs.rs/reqwest-netrc/badge.svg |
| 104 | [doc-url-2]: https://docs.rs/reqwest-netrc |
| 105 | [actions-badge-2]: https://github.com/gribouille/netrc/actions/workflows/reqwest-netrc.yml/badge.svg |
| 106 | [actions-url-2]: https://github.com/gribouille/netrc/actions/workflows/reqwest-netrc.yml |