Crate curs [] [src]

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.

Fork on GitHub

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"]);
}

Reexports

pub extern crate serde;
pub extern crate serde_json;
pub extern crate hyper;

Structs

FileUpload

File uploads are more than just a path to a local file.

MultipartBodyBuilder

You're not expected to be using the MultipartBodyBuilder on your own, Make a Request and it will know when to delegate if there are any files to be posted. It's still exported publicly because it may come in handy for other uses.

Request

The main entry point. Craft your request and send it.

Response

A response for a client request to a remote server.

Enums

CursError

Sending your request may fail for any of the following reasons.

Method

The Request Method (VERB)

StatusCode

An HTTP status code (status-code in RFC 7230 et al.).

Traits

DecodableResult

Type Definitions

CursResult

Your result may be text or a struct deserialized from JSON. The error is always a CursError

Param

And each param is just a &str tuple.

Params

All your params should go in a vector.