4 releases
Uses old Rust 2015
0.1.3 | Aug 20, 2016 |
---|---|
0.1.2 | Apr 24, 2016 |
0.1.1 | Apr 24, 2016 |
0.1.0 | Apr 23, 2016 |
#42 in #multipart
Used in bitex
12KB
188 lines
Curs.
Hyper HTTP client lib, feels more like curl. Supports file Uploads.
It feels like curl,
this HTTP client,
it's built on Hyper,
shoulder of a giant.
Lets you post files,
which is a good start,
it adds its own headers,
makes it multipart.
Decodes Response JSON,
it's good for your REST,
go check some examples,
they're all inside /test.
The code is quite simple,
and easy to digest,
if you want to contribute,
send your pull request.
Installation
[dependencies]
curs = "0.1"
What does it look like?
See actual examples in the docs
License
Licensed under the glorious WTFPL
Essentially public domain, even in jurisdictions where public domain is not a legal option.
lib.rs
:
Curs: Curl for rust users. Based on Hyper. File Uploads. JSON REST API Clients.
Make your request, add params and files, or a JSON body, curs just works and decides the right body format and adds any needed headers.
Adding a raw request body is also possible, but if you need unopinionated flexibility you can try falling back to hyper, re-exported as curs::hyper::client for your convenience.
Then you can optionally deserialize json responses. Or just use them as text.
Examples
// This example pretty much uses the whole library. Notice hyper is re-exported by curs.
// Uploads a file, and some params doing a POST request to a stubbed server.
// The actual curs imports.
extern crate curs;
use curs::{Request, FileUpload, DecodableResult, Method};
// Just stuff needed for this particular test.
extern crate http_stub;
use http_stub as hs;
use std::env;
use curs::hyper::header::UserAgent;
fn main(){
// Nevermind this stub HTTP server. Find the actual curs code below.
let url = hs::HttpStub::run(|s|{ s.send_body(r#"["foo", "bar"]"#) });
let file = FileUpload{
name: "shim.png".to_string(),
mime: None,
path: &env::current_dir().unwrap().join("tests/fixtures/test.png")};
let response : Vec<String> = Request::new(Method::Post, &*format!("{}/some_post", url))
.params(vec![("one","value_one"), ("two", "value_two")])
.header(UserAgent("morcilla-firefox".to_string()))
.files(vec![file])
.send().decode_success().unwrap();
assert_eq!(response, vec!["foo", "bar"]);
}
Dependencies
~7MB
~152K SLoC