Restate Typescript SDK
    Preparing search index...

    RestateEndpoint encapsulates all the Restate services served by this endpoint.

    A RestateEndpoint can be served as:

    For Lambda, check LambdaEndpoint

    A typical endpoint served as HTTP/2 server:

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

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

    Using the HTTP/1.1 handler with your own server:

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

    const endpoint = restate.endpoint().bind(myService);
    const server = http.createServer(endpoint.http1Handler());
    server.listen(8000);

    Using the combined handler with an HTTP/2 server that also accepts HTTP/1.1:

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

    const endpoint = restate.endpoint().bind(myService);
    const server = http2.createSecureServer({ key, cert, allowHTTP1: true }, endpoint.handler());
    server.listen(8000);
    interface RestateEndpoint {
        bind<P extends string, M>(
            service:
                | ServiceDefinition<P, M>
                | VirtualObjectDefinition<P, M>
                | WorkflowDefinition<P, M>,
        ): RestateEndpoint;
        defaultServiceOptions(options: DefaultServiceOptions): RestateEndpoint;
        handler(
            options?: { bidirectional?: boolean },
        ): {
            (request: IncomingMessage, response: ServerResponse): void;
            (request: Http2ServerRequest, response: Http2ServerResponse): void;
        };
        http1Handler(
            options?: { bidirectional?: boolean },
        ): (request: IncomingMessage, response: ServerResponse) => void;
        http2Handler(
            options?: { bidirectional?: boolean },
        ): (request: Http2ServerRequest, response: Http2ServerResponse) => void;
        journalValueCodecProvider(
            codecProvider: () => Promise<JournalValueCodec>,
        ): RestateEndpoint;
        listen(port?: number): Promise<number>;
        setLogger(logger: LoggerTransport): RestateEndpoint;
        withIdentityV1(...keys: string[]): RestateEndpoint;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Returns a combined request handler that auto-detects HTTP/1 vs HTTP/2 requests and dispatches to the appropriate internal handler.

      By default (when bidirectional is omitted), HTTP/2+ requests use bidirectional streaming (BIDI_STREAM) and HTTP/1 requests use request-response mode (REQUEST_RESPONSE).

      Set bidirectional: true to force BIDI_STREAM for all requests, or bidirectional: false to force REQUEST_RESPONSE for all requests.

      This is useful with http2.createSecureServer({ allowHTTP1: true }), where the same server handles both HTTP/1.1 and HTTP/2 connections.

      Parameters

      • Optionaloptions: { bidirectional?: boolean }

      Returns {
          (request: IncomingMessage, response: ServerResponse): void;
          (request: Http2ServerRequest, response: Http2ServerResponse): void;
      }

      const server = http2.createSecureServer(
      { key, cert, allowHTTP1: true },
      endpoint.handler()
      );
      server.listen(port);
    • Returns an http1 server handler.

      By default, this handler operates in request-response protocol mode (REQUEST_RESPONSE), which buffers the full request before sending the response. This is the safest mode for HTTP/1.1 and works across all environments and proxies.

      Set bidirectional: true to enable bidirectional streaming (BIDI_STREAM) for HTTP/1.1 servers that support it. Note that some proxies and clients may not handle HTTP/1.1 bidirectional streaming correctly.

      Parameters

      • Optionaloptions: { bidirectional?: boolean }

      Returns (request: IncomingMessage, response: ServerResponse) => void

      const httpServer = http.createServer(endpoint.http1Handler());
      httpServer.listen(port);
    • Returns an http2 server handler.

      By default, this handler uses bidirectional streaming (BIDI_STREAM). Set bidirectional: false to use request-response mode (REQUEST_RESPONSE).

      See RestateEndpoint.listen for more details.

      Parameters

      • Optionaloptions: { bidirectional?: boolean }

      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 RestateEndpoint.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