# Formatting API Responses

> Standardizes the structure of internal function results. Use when writing Services or Server Actions.

- Skill: `majiayu000/formatting-api-responses` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add majiayu000/formatting-api-responses`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/formatting-api-responses/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/formatting-api-responses

---


# API Response Formatting

## When to use this skill
- Writing any function that fetches or mutates data and is called by the frontend.
- Ensuring the UI knows exactly how to read a "Success" or "Failure".

## Standard Structure
```typescript
{
    success: boolean;
    data?: T;       // The resulting object(s)
    error?: string; // User-friendly error message
    code?: number;  // Optional status code (404, 401, etc.)
}
```

## Example Usage
```typescript
export async function deleteBooking(id: string) {
    try {
        await BookingService.delete(id);
        return { success: true };
    } catch (e) {
        return { success: false, error: "Could not delete booking. Please try again." };
    }
}
```

## Instructions
- **Consistency**: Never return raw error objects to the component; always parse them into a `success: false` structure.

