Staaarter

API Response Examples

A stack of API documentation cards, one per example: a color-coded HTTP status badge and method/path header, a small monospace list of response headers, and the JSON response body in a dark code panel with a one-click copy button. Includes both success and error response shapes, so it doubles as documentation for how failures look, not just the happy path.

By Staaarter Team
DevTools
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button, badge dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/api-response-examples.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/devtools/devtools28.tsx instead.

Usage

The file also exports devtools28Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Devtools28, devtools28Demo } from "@/components/blocks/devtools/devtools28";

export default function Page() {
  return <Devtools28 {...devtools28Demo} />;
}

Props

PropTypeDefaultDescription
headingstring"Example responses"Section heading.
descriptionstring"Sample requests and responses for the endpoints you'll hit most often, including how errors come back."Section intro text below the heading.
examplesApiExample[]noneExample cards, rendered in order.
classNamestringnoneExtra classes for the outer section element.

Types

type ApiHeader = { name: string; value: string };

type ApiExample = {
  method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
  path: string;
  status: number;
  statusText: string;
  headers: ApiHeader[];
  /** Pretty-printed JSON body shown verbatim in the code panel and copied as-is. */
  body: string;
};

Behavior notes

  • Status badge color is derived from the numeric status field at render time: >= 500 is red, >= 400 (and < 500) is amber, anything else is emerald. It reacts to whatever status you pass in, it does not require you to also pick a variant.
  • The copy button is real: it calls navigator.clipboard.writeText with that card's exact body string and swaps its icon to a checkmark for two seconds. Each card tracks its own copied state independently, so copying one card's body does not affect another card's button.
  • The body is rendered as a plain preformatted string, there is no client-side JSON.parse or re-formatting of it; whatever string you pass in body is exactly what's shown and copied, so make sure it's already pretty-printed the way you want it displayed.
  • This block needs "use client" only for the clipboard interaction; nothing about the layout itself requires it.