Struct knock::HTTP [−][src]
pub struct HTTP { pub response: Response, pub url: Url, pub method: String, pub body: HashMap<String, Data>, pub header: HashMap<String, String>, // some fields omitted }
HTTP struct
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/date").unwrap();
Fields
response: Response
url: Url
method: String
body: HashMap<String, Data>
header: HashMap<String, String>
Methods
impl HTTP
[src]
impl HTTP
pub fn new(url: &str) -> Result<HTTP, HttpError>
[src]
pub fn new(url: &str) -> Result<HTTP, HttpError>
HTTP struct instance
extern crate knock; let mut http = match knock::HTTP::new("https://example.com/api/date") { Ok(http) => http, Err(err) => panic!(err) };
pub fn get(&mut self) -> &mut Self
[src]
pub fn get(&mut self) -> &mut Self
How to send simple GET request
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/date").unwrap(); http.get().send();
pub fn post(&mut self) -> &mut Self
[src]
pub fn post(&mut self) -> &mut Self
How to send simple POST request
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/date").unwrap(); http.post().send();
pub fn put(&mut self) -> &mut Self
[src]
pub fn put(&mut self) -> &mut Self
How to send simple PUT request
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/date").unwrap(); http.put().send();
pub fn delete(&mut self) -> &mut Self
[src]
pub fn delete(&mut self) -> &mut Self
How to send simple DELETE request
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/date").unwrap(); http.delete().send();
pub fn danger_accept_invalid_certs(
&mut self,
danger_accept_invalid_certs: bool
) -> &mut Self
[src]
pub fn danger_accept_invalid_certs(
&mut self,
danger_accept_invalid_certs: bool
) -> &mut Self
Disable SSL validation before performing a GET request
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/date").unwrap(); http.danger_accept_invalid_certs(true).get().send();
pub fn request(&mut self, method: &str) -> &mut Self
[src]
pub fn request(&mut self, method: &str) -> &mut Self
Send custom Request
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/data").unwrap(); http.request("OPTIONS").send();
pub fn body(&mut self, data: HashMap<String, Data>) -> &mut Self
[src]
pub fn body(&mut self, data: HashMap<String, Data>) -> &mut Self
Send Body data as HashMap<String, Data>
extern crate knock; use std::collections::HashMap; let mut http = knock::HTTP::new("https://example.com/api/data").unwrap(); let mut body: HashMap<String, knock::Data> = HashMap::new(); body.insert("key".to_string(), knock::Data::String("value".to_string())); http.post().body(body).send();
pub fn body_as_str(&mut self, data: &str) -> &mut Self
[src]
pub fn body_as_str(&mut self, data: &str) -> &mut Self
You also can use body_as_str function for sending body as String
extern crate knock; let mut http = knock::HTTP::new("https://example.com/api/data").unwrap(); http.post().body_as_str("{\"key\": \"value\"}").send();
But you need to set Content-Type in header, default Content-Type
pub fn header(&mut self, data: HashMap<String, String>) -> &mut Self
[src]
pub fn header(&mut self, data: HashMap<String, String>) -> &mut Self
Send Body data as HashMap<String, Data>
extern crate knock; use std::collections::HashMap; let mut http = knock::HTTP::new("https://example.com/api/data").unwrap(); let mut body: HashMap<String, knock::Data> = HashMap::new(); let mut header: HashMap<String, String> = HashMap::new(); body.insert("key".to_string(), knock::Data::String("value".to_string())); header.insert("Content-Type".to_string(), "application/json".to_string()); http.post().body(body).header(header).send();
pub fn send(&mut self) -> Result<Response, HttpError>
[src]
pub fn send(&mut self) -> Result<Response, HttpError>
Send Body data as HashMap<String, Data>
extern crate knock; use std::collections::HashMap; let mut http = knock::HTTP::new("https://example.com/api/data").unwrap(); let mut body: HashMap<String, knock::Data> = HashMap::new(); body.insert("key".to_string(), knock::Data::String("value".to_string())); match http.post().body(body).send() { Ok(res) => println!("{:?}", res), Err(err) => println!("{:?}", err) };