Crates.io | runestick-http |
lib.rs | runestick-http |
version | 0.3.0 |
source | src |
created_at | 2020-08-07 15:30:29.002159 |
updated_at | 2020-09-02 17:17:08.705398 |
description | An HTTP module based on reqwest for runestick. |
homepage | https://github.com/rune-rs/rune |
repository | https://github.com/rune-rs/rune |
max_upload_size | |
id | 274034 |
size | 7,645 |
HTTP module for runestick based on reqwest.
Add the following to your Cargo.toml
:
runestick = "0.2"
runestick-http = "0.2"
# not necessary, but useful
runestick-json = "0.2"
Install it into your context:
let mut context = runestick::Context::with_default_packages()?;
context.install(runestick_http::module()?)?;
context.install(runestick_json::module()?)?;
Use it in Rune:
use http;
use json;
fn main() {
let client = http::Client::new();
let response = client.get("http://worldtimeapi.org/api/ip");
let text = response.text();
let json = json::from_string(text);
let timezone = json["timezone"];
if timezone is String {
dbg(timezone);
}
let body = json::to_bytes(#{"hello": "world"});
let response = client.post("https://postman-echo.com/post")
.body_bytes(body)
.send();
let response = json::from_string(response.text());
dbg(response);
}