#wasmcloud #actor #webassembly #capability

wasmcloud-interface-httpserver

interface for actors to receive http requests (wasmcloud:httpserver)

25 releases (11 breaking)

0.12.0 Sep 19, 2023
0.11.0 Jul 20, 2023
0.10.0 Apr 12, 2023
0.9.0 Dec 20, 2022
0.1.0 Jul 23, 2021

#138 in WebAssembly

Download history 181/week @ 2023-11-02 189/week @ 2023-11-09 163/week @ 2023-11-16 243/week @ 2023-11-23 395/week @ 2023-11-30 203/week @ 2023-12-07 170/week @ 2023-12-14 157/week @ 2023-12-21 88/week @ 2023-12-28 134/week @ 2024-01-04 134/week @ 2024-01-11 116/week @ 2024-01-18 160/week @ 2024-01-25 550/week @ 2024-02-01 170/week @ 2024-02-08 268/week @ 2024-02-15

1,171 downloads per month

Apache-2.0 and maybe LGPL-3.0-or-later

27KB
570 lines

crates.io  TinyGo Version

wasmCloud HTTP Server Interface

This is the interface for an HTTP Server capability with the contract ID wasmcloud:httpserver

This folder contains

  • Model definition for wasmcloud:httpserver
  • Generated documentation (in HTML)
  • Generated Rust library (in Rust)

Any Rust actor or capability provider using wasmcloud:httpserver should rely upon this library. A capability provider implements the trait HttpServerReceiver.

Capability Provider Implementations

The following is a list of implementations of the wasmcloud:httpserver contract. Feel free to submit a PR adding your implementation if you have a community/open source version.

Name Vendor Description
HTTPServer wasmCloud wasmCloud HTTP Server implementation using the highly scalable warp web server.

Example Usage

🦀 Rust

Implementing the HttpServer.HandleRequest operation

use wasmbus_rpc::actor::prelude::*;
use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver};

#[derive(Debug, Default, Actor, HealthResponder)]
#[services(Actor, HttpServer)]
struct HelloActor {}

#[async_trait]
impl HttpServer for HelloActor {
    async fn handle_request(&self, _ctx: &Context, _req: &HttpRequest) -> RpcResult<HttpResponse> {
        Ok(HttpResponse {
            body: "Hello World".as_bytes().to_owned(),
            ..Default::default()
        })
    }
}

🐭Golang

Implementing the HttpServer.HandleRequest operation

import (
	"github.com/wasmcloud/actor-tinygo"
	httpserver "github.com/wasmcloud/interfaces/httpserver/tinygo"
)

func main() {
	me := Actor{}

	actor.RegisterHandlers(httpserver.HttpServerHandler(&me))
}

type Actor struct {}

func (e *Actor) HandleRequest(ctx *actor.Context, req httpserver.HttpRequest) (*httpserver.HttpResponse, error) {
	r := httpserver.HttpResponse{
		StatusCode: 200,
		Header:     make(httpserver.HeaderMap, 0),
		Body:       []byte("hello world"),
	}
	return &r, nil
}

Dependencies

~13–32MB
~506K SLoC