Skip to content

Conversation

@Kaveh-ap
Copy link

Summary

Add a BodyViewer component for displaying request/response bodies with JSON tree viewing and text fallback, plus initial expansion controls throughout RequestDetails. Also fix Header rendering to avoid array children in Text.

Motivation

  • Improve readability of large JSON payloads with a collapsible tree.
  • Provide better defaults via initial expansion controls for sections (headers and bodies).

Changes

  • New component: BodyViewer
    • Detects JSON strings and renders a collapsible tree; falls back to text view.
    • iOS uses read-only TextInput for large content rendering reliability.
    • Supports data prop to bypass parsing and render prepared JSON.
    • Basic styling and nested scroll support for better UX.
  • RequestDetails enhancements
    • New props:
      • initialRequestHeadersExpanded?: boolean (default: true)
      • initialResponseHeadersExpanded?: boolean (default: true)
      • initialRequestBodyExpanded?: boolean (default: true)
      • initialResponseBodyExpanded?: boolean (default: true)
    • Uses BodyViewer for request/response bodies with collapsible sections.
    • Adds “Share full request” and “Share as cURL” actions.
  • Header fix
    • Concatenate the collapsible indicator and title into a single string to avoid array children in Text.
    • Indicator ▼/▶ shows only when collapsible.

Usage

<RequestDetails
  request={request}
  onClose={close}
  initialRequestHeadersExpanded={true}
  initialResponseHeadersExpanded={false}
  initialRequestBodyExpanded={true}
  initialResponseBodyExpanded={false}
/>

If you want to directly render JSON data:

<BodyViewer data={{ foo: 'bar', list: [1, 2, 3] }} initiallyExpanded />

UI/UX

  • JSON bodies: Collapsible, indented view with alternating backgrounds per level.
  • Text bodies: Scrollable view; on iOS uses read-only TextInput for large content stability.

Backward Compatibility

  • Defaults keep previous behavior (all sections expanded initially).
  • No breaking API changes.

Testing

  • All tests pass.
  • Header tests fixed by ensuring Text receives a single string.
  • Manual checks for:
    • Collapsible behavior for headers and bodies.
    • JSON parse vs. plain text fallback.
    • Share actions.

Performance

  • JSON parsing only when content is a string and data isn’t provided.
  • Tree rendering uses toggling to limit on-screen content.

Screenshots/GIFs

Screenshot 1 Screenshot 2

Screenshot 3 Screenshot 4

Kaveh added 2 commits October 26, 2025 15:57
…unctionality

- Updated Header component to support collapsible behavior with toggle functionality.
- Modified RequestDetails component to utilize collapsible headers for request and response bodies.
- Adjusted styles for better presentation and usability.
- Introduced compact prop in RequestDetails for improved layout control.
…or RequestDetails

- Added BodyViewer component to handle JSON and text content display with collapsible functionality.
- Enhanced RequestDetails component to support initial expansion states for request and response headers and bodies.
- Updated README to document new features and usage examples for initial expansion controls.
@seyedmostafahasani
Copy link

@alexbrazier
Would you please check this PR?
I think it is very useful.

@Kaveh-ap
Thanks for creating this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants