send

Function send 

Source
pub fn send(request: Request) -> Result<Response, SendError>
Expand description

Send an outgoing request.

Requires http permissions to be set in the plugin configuration for any domain or host this function will be making requests to. In the example below, this would require the http permission value to be set to at least ["www.example.com"].

Note that if an HTTP request version is set, it will be ignored because the underlying wasi-http API abstracts HTTP version and transport protocol choices.

ยงExample

use bulwark_sdk::*;
use std::collections::HashMap;

pub struct HttpExample;

#[bulwark_plugin]
impl HttpHandlers for HttpExample {
    fn handle_request_decision(
        _request: http::Request,
        _labels: HashMap<String, String>,
    ) -> Result<HandlerOutput, Error> {
        let _response = http::send(
            http::request::Builder::new()
                .method("GET")
                .uri("http://www.example.com/")
                .body(Bytes::new())?,
        )?;
        // Do something with the response

        Ok(HandlerOutput::default())
    }
}