• createApiServer is the primary method through which your server code will interact with estuary-rpc. Calling it will set up and start an 'http' server that listens for HTTP and WS connections and appropriately forwards data to your endpoint implementations, taking into account underlying transport encodeings, authentication tokens, and the wonkiness of dealing with WebSockets

    Example

    // Common Code
    export interface ExampleApi<Closure, Meta> extends Api<Closure, Meta> {
    foo: FooService<Closure, Meta>;
    fileUpload: Endpoint<void, void, Closure, Meta>;
    }

    export interface FooService<Closure, Meta> extends Api<Closure, Meta> {
    emptyPost: Endpoint<void, void, Closure, Meta>;
    simpleGet: Endpoint<number, number, Closure, Meta>;
    simpleStream: StreamDesc<string, boolean, Closure, Meta>;
    }

    export const exampleApiMeta: ExampleApi<never, ExampleMeta> = {
    foo: {
    emptyPost: post("foo/emptyPost"),
    simpleGet: get("foo/simpleGet", { authentication: "bearer", token: "" }),
    simpleStream: ws("foo/simpleStream"),
    },
    fileUpload: post("fileUpload", { uploads: ["someFile.txt"] }),
    };

    // Server Code
    const server: ExampleApi<ApiContext, unknown> = {
    foo: {
    emptyPost: async () => {
    console.log("got post");
    },
    simpleGet: async (num: number) => 4,
    simpleStream: async ({ server }: Duplex<string, boolean>) => {
    server.on("message", (input: string) => {
    console.log("Got message", input);
    server.write(input === "foo");
    });
    },
    } as FooService<ApiContext, unknown>,

    fileUpload: (_1: void, _2: ApiContext) => {
    return null;
    },
    };

    Type Parameters

    Parameters

    • api: ApiTypeOf<ApiContext, unknown, T>

      Your API definition, the collection of all the endpoint implementations

    • apiMeta: ApiTypeOf<unknown, Meta, T>
    • serverOpts: ServerOpts<Meta>

      options for configuring the server *

    Returns void

Generated using TypeDoc