taubyte_sdk/http/client/
methods.rs1use super::{response::Response, Client};
2use http::{method, request::Builder, Uri};
3
4fn send_helper(builder: Builder) -> Result<Response, Box<dyn std::error::Error>> {
5 let client = Client::new()?;
6 client.send_without_body(builder)
7}
8
9impl Client {
10 pub fn get<T>(uri: T) -> Result<Response, Box<dyn std::error::Error>>
11 where
12 Uri: TryFrom<T>,
13 <Uri as TryFrom<T>>::Error: Into<http::Error>,
14 {
15 send_helper(
16 http::Request::builder()
17 .uri(uri)
18 .method(method::Method::GET),
19 )
20 }
21
22 pub fn post<T>(uri: T) -> Result<Response, Box<dyn std::error::Error>>
23 where
24 Uri: TryFrom<T>,
25 <Uri as TryFrom<T>>::Error: Into<http::Error>,
26 {
27 send_helper(
28 http::Request::builder()
29 .uri(uri)
30 .method(method::Method::POST),
31 )
32 }
33
34 pub fn put<T>(uri: T) -> Result<Response, Box<dyn std::error::Error>>
35 where
36 Uri: TryFrom<T>,
37 <Uri as TryFrom<T>>::Error: Into<http::Error>,
38 {
39 send_helper(
40 http::Request::builder()
41 .uri(uri)
42 .method(method::Method::PUT),
43 )
44 }
45
46 pub fn delete<T>(uri: T) -> Result<Response, Box<dyn std::error::Error>>
47 where
48 Uri: TryFrom<T>,
49 <Uri as TryFrom<T>>::Error: Into<http::Error>,
50 {
51 send_helper(
52 http::Request::builder()
53 .uri(uri)
54 .method(method::Method::DELETE),
55 )
56 }
57
58 pub fn head<T>(uri: T) -> Result<Response, Box<dyn std::error::Error>>
59 where
60 Uri: TryFrom<T>,
61 <Uri as TryFrom<T>>::Error: Into<http::Error>,
62 {
63 send_helper(
64 http::Request::builder()
65 .uri(uri)
66 .method(method::Method::HEAD),
67 )
68 }
69}