From b493bc3c8436be9812a58e7ddaf3777df642836c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 26 Feb 2019 16:47:35 +0100 Subject: [PATCH] docs(lib): Document available features and update example --- src/lib.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9374460d2..90c216dc7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,22 +9,21 @@ //! dependencies or sacrificing too much usability. //! //! Using `crimp` to make HTTP requests is done using a simple -//! builder-pattern style API: +//! builder-pattern style API. For example, to make a `GET`-request +//! and print the result to `stdout`: //! //! ```rust //! use crimp::{Method, Request}; //! //! let response = Request::new(Method::Get, "http://httpbin.org/get") //! .user_agent("crimp test suite").unwrap() -//! .send().unwrap(); +//! .send().unwrap() +//! .as_string().unwrap(); //! -//! assert_eq!(response.status, 200); +//! println!("Status: {}\nBody: {}", response.status, response.body); +//! # assert_eq!(response.status, 200); //! ``` //! -//! The `json` feature (enabled by default) adds support for -//! automatically serialising and deserialising request/response -//! bodies using `serde_json`. -//! //! If a feature from the underlying cURL library is missing, the //! `Request::raw` method can be used as an escape hatch to deal with //! the handle directly. Should you find yourself doing this, please @@ -34,6 +33,20 @@ //! cURL Easy handle, meaning that keep-alive of HTTP connections and //! the like is not supported. //! +//! ## Cargo features +//! +//! `crimp` has several optional features, all of which are enabled by +//! default: +//! +//! * `json`: Adds `Request::json` and `Response::as_json` methods +//! which can be used for convenient serialisation of +//! request/response bodies using `serde_json`. This feature adds a +//! dependency on the `serde` and `serde_json` crates. +//! +//! * `basic_auth`: Adds a `Request::basic_auth` utility method to set +//! a basic authentication header on the request. This feature adds +//! a dependency on the `base64` crate. +//! //! [cURL Rust bindings]: https://docs.rs/curl //! [reqwest]: https://docs.rs/reqwest //! [file an issue]: https://github.com/tazjin/crimp/issues