Skip to content

Add getJsonBody util to plugin-sdk and document it #263

@0xtsukino

Description

@0xtsukino

Add getJsonBody util to plugin-sdk and document it

relates to #239


Decoding Raw JSON Body
For JSON POST requests, the body is in raw[].bytes as a number array:

function getJsonBody(request) {
  if (!request.requestBody?.raw?.[0]?.bytes) return null;

  // Convert number array to string
  const bytes = request.requestBody.raw[0].bytes;
  const text = String.fromCharCode(...bytes);

  try {
    return JSON.parse(text);
  } catch {
    return text;
  }
}

function main() {
  const requests = useRequests({ method: 'POST' });

  const targetRequest = requests.find(r => r.url.includes('/api/endpoint'));
  if (targetRequest) {
    const body = getJsonBody(targetRequest);
    // Use body data...
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions