Documentation
    Preparing search index...

    RestateEndpoint encapsulates all the Restate services served by this endpoint.

    A RestateEndpoint can either be served either as HTTP2 server, using the methods listen or http2Handler, or as Lambda, using the method lambdaHandler.

    A typical endpoint served as HTTP server would look like this:

    import * as restate from "@restatedev/restate-sdk";

    restate
    .endpoint()
    .bind(myService)
    .listen(8000);

    A typical endpoint served as AWS Lambda would look like this:

    import * as restate from "@restatedev/restate-sdk/lambda";

    export const handler = restate
    .endpoint()
    .bind(myService)
    .handler();
    interface RestateEndpoint {
        bind<P extends string, M>(
            service:
                | ServiceDefinition<P, M>
                | VirtualObjectDefinition<P, M>
                | WorkflowDefinition<P, M>,
        ): RestateEndpoint;
        http2Handler(): (
            request: Http2ServerRequest,
            response: Http2ServerResponse,
        ) => void;
        listen(port?: number): Promise<number>;
        setLogger(logger: LoggerTransport): RestateEndpoint;
        withIdentityV1(...keys: string[]): RestateEndpoint;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Returns an http2 server handler. See listen for more details.

      Returns (request: Http2ServerRequest, response: Http2ServerResponse) => void

    • Serve this Restate Endpoint as HTTP2 server, listening to the given port.

      If the port is undefined, this method will use the port set in the PORT environment variable. If that variable is undefined as well, the method will default to port 9080.

      The returned promise resolves with the bound port when the server starts listening, or rejects with a failure otherwise.

      This method is a shorthand for:

      Parameters

      • Optionalport: number

        The port to listen at. May be undefined (see above).

      Returns Promise<number>

      a Promise that resolves with the bound port, or rejects with a failure otherwise.

      const httpServer = http2.createServer(endpoint.http2Handler());
      httpServer.listen(port);

      If you need to manually control the server lifecycle, we suggest to manually instantiate the http2 server and use http2Handler.

    • Replace the default console-based LoggerTransport

      Parameters

      Returns RestateEndpoint

      Using console:

      restate.setLogger((meta, message, ...o) => {console.log(`${meta.level}: `, message, ...o)})
      

      Using winston:

      const logger = createLogger({ ... })
      restate.setLogger((meta, message, ...o) => {logger.log(meta.level, {invocationId: meta.context?.invocationId}, [message, ...o].join(' '))})

      Using pino:

      const logger = pino()
      restate.setLogger((meta, message, ...o) => {logger[meta.level]({invocationId: meta.context?.invocationId}, [message, ...o].join(' '))})
    • Provide a list of v1 request identity public keys eg publickeyv1_2G8dCQhArfvGpzPw5Vx2ALciR4xCLHfS5YaT93XjNxX9 to validate incoming requests against, limiting requests to Restate clusters with the corresponding private keys. This public key format is logged by the Restate process at startup if a request identity private key is provided.

      If this function is called, all incoming requests irrelevant of endpoint type will be expected to have x-restate-signature-scheme: v1 and x-restate-jwt-v1: <valid jwt signed with one of these keys>. If not called,

      Parameters

      • ...keys: string[]

      Returns RestateEndpoint