#webassembly #wasm #wasmcloud #actor

wasmcloud-actor-http-client

HTTP Client Actor Interface for wasmCloud Actors

4 releases

0.2.1 Apr 16, 2021
0.2.0 Mar 25, 2021
0.1.1 Feb 17, 2021
0.1.0 Feb 10, 2021

#21 in #wasmcloud

Download history 5/week @ 2021-02-20 8/week @ 2021-02-27 7/week @ 2021-03-06 19/week @ 2021-03-13 22/week @ 2021-03-20 21/week @ 2021-03-27 7/week @ 2021-04-03 19/week @ 2021-04-10 25/week @ 2021-04-17 6/week @ 2021-04-24 7/week @ 2021-05-01 6/week @ 2021-05-08 24/week @ 2021-05-15 1/week @ 2021-05-22 5/week @ 2021-05-29 6/week @ 2021-06-05

59 downloads per month
Used in wasmcloud-httpclient

Apache-2.0

10KB
109 lines

crates.io  Rust license  documentation

wasmCloud HTTP Client Actor Interface

This crate provides wasmCloud actors with an interface to the HTTP client capability provider. Actors using this interface must have the claim wasmcloud:httpclient in order to have permission to make outbound HTTP requests, and they must have an active, configured binding to an HTTP Client capability provider.

wasmCloud actors without this permission and capability binding will be unable to make outbound HTTP requests.

Example:

use wapc_guest::HandlerResult;
extern crate wasmcloud_actor_http_server as httpserver;
extern crate wasmcloud_actor_http_client as httpclient;
extern crate wasmcloud_actor_core as actor;

const API_URL: &str = "https://wasmcloudapi.cloud.io/proxy";

#[actor::init]
pub fn init() {
    httpserver::Handlers::register_handle_request(get_proxy);
}

/// This function proxys an inbound HTTP request to an external server
fn get_proxy(msg: httpserver::Request) -> HandlerResult<httpserver::Response> {
    // Form client request from server request
    if msg.method == "GET".to_string() {
        // Replace `request` with `httpclient::default().request`
        let res = request(msg.method, API_URL.to_string(), msg.header, vec![])?;
        // Form server response
        Ok(httpserver::Response {
            status_code: res.status_code,
            status: res.status,
            header: res.header,
            body: res.body,
        })
    } else {
        Ok(httpserver::Response::internal_server_error("Only GET requests can be proxied with this actor"))
    }
}

Dependencies

~1–1.7MB
~37K SLoC