Interface Handler

Source
Expand description

The shape of a handler file's default export. You can export a single handler or an array of them.

example
import type { Handler } from "llm-mock-server";
export default {
match: (req) => req.lastMessage.includes("echo"),
respond: (req) => `Echo: ${req.lastMessage}`,
} satisfies Handler;
interface Handler {
    match: (req: MockRequest) => boolean;
    respond: (req: MockRequest) => Reply | Promise<Reply>;
}

Properties§

§match: { ... }

Return true if this handler should respond to the request.

§respond: { ... }

Produce the reply for a matched request. Can be async.