Mocky Balboa API Reference
    Preparing search index...

    Message builder

    Creating a RESPONSE message

    // Create the message
    const responseMessage = new Message(MessageType.RESPONSE, {
    id: "123",
    response: {
    status: 200,
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ message: "Hello, world!" }),
    },
    });

    // Send the message on the WebSocket connection
    ws.send(responseMessage.toString());

    Type Parameters

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Type Parameters

      • T extends MessageType
      • P extends
            | Record<string, never>
            | { id: string }
            | {
                id: string;
                request: {
                    body?: string;
                    headers: Record<string, string>;
                    method: string;
                    url: string;
                };
            }
            | {
                error?: boolean;
                id: string;
                response?: {
                    body?: string;
                    headers: Record<string, string>;
                    path?: string;
                    status: number;
                };
            }
            | { id: string; message: string }

      Parameters

      • type: T
      • payload: P
      • OptionalmessageId: string

      Returns Message<T, P>

    Properties

    messageId: string

    Methods