stk-http

Crates.iostk-http
lib.rsstk-http
version0.2.1
sourcesrc
created_at2020-08-06 13:16:55.830227
updated_at2020-08-06 13:27:47.982961
descriptionAn HTTP module based on reqwest for STK.
homepagehttps://github.com/udoprog/stk
repositoryhttps://github.com/udoprog/stk
max_upload_size
id273655
size6,284
John-John Tedro (udoprog)

documentation

https://docs.rs/stk-http

README

Build Status

stk-http

HTTP module for stk based on reqwest.

Usage

Add the following to your Cargo.toml:

stk = "0.2"
stk-http = "0.2"
# not necessary, but useful
stk-json = "0.2"

Install it into your context:

let mut context = stk::Context::with_default_packages()?;
context.install(stk_http::module()?)?;
context.install(stk_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);
}
Commit count: 1290

cargo fmt