T402 API Reference - v2.8.0
    Preparing search index...

    Function declareDiscoveryExtension

    • Create a discovery extension for any HTTP method

      This function helps servers declare how their endpoint should be called, including the expected input parameters/body and output format.

      Parameters

      • config: Omit<DeclareDiscoveryExtensionConfig, "method">

        Configuration object for the discovery extension

      Returns Record<string, DiscoveryExtension>

      A discovery extension object with both info and schema

      // For a GET endpoint with no input
      const getExtension = declareDiscoveryExtension({
      method: "GET",
      output: {
      example: { message: "Success", timestamp: "2024-01-01T00:00:00Z" }
      }
      });

      // For a GET endpoint with query params
      const getWithParams = declareDiscoveryExtension({
      method: "GET",
      input: { query: "example" },
      inputSchema: {
      properties: {
      query: { type: "string" }
      },
      required: ["query"]
      }
      });

      // For a POST endpoint with JSON body
      const postExtension = declareDiscoveryExtension({
      method: "POST",
      input: { name: "John", age: 30 },
      inputSchema: {
      properties: {
      name: { type: "string" },
      age: { type: "number" }
      },
      required: ["name"]
      },
      bodyType: "json",
      output: {
      example: { success: true, id: "123" }
      }
      });