#header #body #string #hash-map #rust

knock

Knock is a simple HTTP Client for Rust

9 releases

Uses old Rust 2015

0.1.8 Aug 13, 2018
0.1.7 Jul 5, 2018
0.1.6 Nov 13, 2017
0.1.5 May 19, 2017
0.1.4 Apr 24, 2017

#474 in HTTP client


Used in 2 crates

MPL-2.0 license

24KB
458 lines

knock

Build Status Build status Crates.io

Knock is a simple HTTP Client for Rust

Documentation

Installation

# Cargo.toml

[dependencies]
knock = "0.1"

Usage

An example client looks like:

extern crate knock;

use knock::HTTP;

fn main() {
    let http = HTTP::new("https://google.com").unwrap();
    let response = http.get().send();
}

For sending POST requests with custom headers

extern crate knock;

use knock::HTTP;
use std::collections::HashMap;

fn main() {
    let http = HTTP::new("https://google.com").unwrap();
    let mut body = HashMap::new();
    let mut headers = HashMap::new();

    body.insert("file", Data::File("/path/to/file.file"));
    body.insert("field", Data::String("value"));

    headers.insert("Content-Type", "multipart/form-data");

    let response = http.post().body(body).header(headers).send();
}

License

knock is primarily distributed under the terms of Mozilla Public License 2.0.

See LICENSE for details.

Dependencies

~2–12MB
~171K SLoC