Module http_server

Source
Expand description

§Serving

Restate services run as an HTTP endpoint.

§Creating an HTTP endpoint

  1. Create the endpoint
  2. Bind one or multiple services to it.
  3. Listen on the specified port (default 9080) for connections and requests.
use restate_sdk::endpoint::Endpoint;
use restate_sdk::http_server::HttpServer;

#[tokio::main]
async fn main() {
    HttpServer::new(
        Endpoint::builder()
            .bind(MyServiceImpl.serve())
            .bind(MyVirtualObjectImpl.serve())
            .bind(MyWorkflowImpl.serve())
            .build(),
    )
    .listen_and_serve("0.0.0.0:9080".parse().unwrap())
    .await;
}

§Validating request identity

SDKs can validate that incoming requests come from a particular Restate instance. You can find out more about request identity in the Security docs. Add the identity key to your endpoint as follows:

    HttpServer::new(
        Endpoint::builder()
            .bind(MyServiceImpl.serve())
            .identity_key("publickeyv1_w7YHemBctH5Ck2nQRQ47iBBqhNHy4FV7t2Usbye2A6f")
            .unwrap()
            .build(),
    )
    .listen_and_serve("0.0.0.0:9080".parse().unwrap())
    .await;

Structs§

HttpServer
Http server to expose your Restate services.