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:

```rust use wapcguest::HandlerResult; extern crate wasmcloudactorhttpserver as httpserver; extern crate wasmcloudactorhttpclient as httpclient; extern crate wasmcloudactor_core as core;

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

[no_mangle]

pub fn wapcinit() { httpserver::Handlers::registerhandlerequest(getproxy); core::Handlers::registerhealthrequest(health); }

fn health(_: core::HealthCheckRequest) -> HandlerResult { Ok(core::HealthCheckResponse::healthy())
}

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