Struct web::XMLHttpRequest
source · pub struct XMLHttpRequest(_);
Implementations§
source§impl XMLHttpRequest
impl XMLHttpRequest
sourcepub fn new() -> XMLHttpRequest
pub fn new() -> XMLHttpRequest
Examples found in repository?
src/http_request.rs (line 152)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}
sourcepub fn open(&self, method: &str, url: &str)
pub fn open(&self, method: &str, url: &str)
Examples found in repository?
src/http_request.rs (line 163)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}
sourcepub fn send(&self)
pub fn send(&self)
Examples found in repository?
src/http_request.rs (line 167)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}
sourcepub fn send_with_body(&self, body: &str)
pub fn send_with_body(&self, body: &str)
Examples found in repository?
src/http_request.rs (line 165)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}
sourcepub fn set_request_header(&self, key: &str, value: &str)
pub fn set_request_header(&self, key: &str, value: &str)
Examples found in repository?
src/http_request.rs (line 171)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}
sourcepub fn response_status(&self) -> usize
pub fn response_status(&self) -> usize
Examples found in repository?
src/http_request.rs (line 175)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}
sourcepub fn response_text(&self) -> String
pub fn response_text(&self) -> String
Examples found in repository?
src/http_request.rs (line 176)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}
pub fn response_header(&self, key: &str) -> String
sourcepub fn set_on_load(&self, callback: impl FnMut() + Send + 'static)
pub fn set_on_load(&self, callback: impl FnMut() + Send + 'static)
Examples found in repository?
src/http_request.rs (lines 174-178)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pub fn fetch(
url: &str,
action: HTTPMethod,
body: Option<&str>,
headers: Option<HashMap<String, String>>,
mut callback: impl FnMut(usize, String) + Send + 'static,
) {
let request = Arc::new(XMLHttpRequest::new());
let r2 = request.clone();
let method_str = match action {
HTTPMethod::GET => "GET",
HTTPMethod::POST => "POST",
HTTPMethod::PUT => "PUT",
HTTPMethod::DELETE => "DELETE",
HTTPMethod::HEAD => "HEAD",
HTTPMethod::OPTIONS => "OPTIONS",
HTTPMethod::PATCH => "PATCH",
};
request.open(method_str, url);
if let Some(body) = body {
request.send_with_body(body);
} else {
request.send();
}
if let Some(headers) = headers {
for (key, value) in headers {
request.set_request_header(&key, &value);
}
}
request.set_on_load(move || {
let status = r2.response_status();
let text = r2.response_text();
callback(status, text);
});
}