1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::{Method, Request, URL};

/// Sends a request to `url` with `method`, returns the response or
/// an [`Error`](https://doc.rust-lang.org/std/io/struct.Error.html).
///
/// In most cases it is recommended to use one of the aliases of this
/// function: [`get`](fn.get.html), [`head`](fn.head.html),
/// [`post`](fn.post.html), [`put`](fn.put.html),
/// [`delete`](fn.delete.html), [`trace`](fn.trace.html),
/// [`options`](fn.options.html), [`connect`](fn.connect.html),
/// [`patch`](fn.patch.html). They omit the `method` parameter, since
/// it is implied in the name, and the body is as optional as it is on
/// [Wikipedia](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Summary_table).
pub fn create_request<T: Into<URL>>(method: Method, url: T) -> Request {
    Request::new(method, url.into())
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Get](enum.Method.html).
pub fn get<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Get, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Head](enum.Method.html).
pub fn head<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Head, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Post](enum.Method.html).
pub fn post<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Post, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Put](enum.Method.html).
pub fn put<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Put, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Delete](enum.Method.html).
pub fn delete<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Delete, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Connect](enum.Method.html).
pub fn connect<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Connect, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Options](enum.Method.html).
pub fn options<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Options, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Trace](enum.Method.html).
pub fn trace<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Trace, url)
}

/// Alias for [send](fn.send.html) with `method` set to
/// [Method::Patch](enum.Method.html).
pub fn patch<T: Into<URL>>(url: T) -> Request {
    create_request(Method::Patch, url)
}