• createApiClient is the primary method by your client will interact with estuary-rpc (unless you also want to generate an OpenApi spec with createOpenApiSpec and use that)

    Returns

    Your API Client object, chalk full of correctly typed callable endpoints

    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"] }),
    };

    // Client Code
    const client = createApiClient(exampleApiMeta, {authentication: "bearer", token: "foo"});
    // posts data, returns nothing
    await client.foo.emptyPost();
    // Gets from server, using Bearer Authentication
    const a = client.foo.simpleGet("hello");
    // Streams data from the server
    streamHandler.on("message", (val: boolean) =>
    console.log("Got message from server", val);
    streamHandler.close()
    );
    streamHandler.write("yooo");

    Type Parameters

    • Meta extends SimpleMeta

      Your custom Metadata class, or just SimpleMeta

    • CustomApi extends Api<unknown, Meta>

      Your API definition type, shared in common with your server

    Parameters

    • api: CustomApi

      Your API Metadata definition, shared in common with your server

    • Optional opts: ClientOpts

      Options for the estuary-rpc-client to use in constructing the underlying HTTP/WS request (most usefully containing an Authentication

    Returns ApiTypeOf<FetchOpts, Meta, CustomApi>

Generated using TypeDoc