.do
Integration

responses

Response formatting and handling

responses

Response formatting and handling with automatic serialization, content negotiation, and error formatting for consistent API responses.

Overview

The responses primitive standardizes HTTP response formatting across all services, handling serialization, headers, status codes, and error messages automatically.

Quick Example

import { responses } from 'sdk.do'

// Success response
return responses.ok({
  user: { id: '123', name: 'Alice' },
})

// Created response
return responses.created(
  {
    order: { id: '456', total: 99.99 },
  },
  {
    location: '/orders/456',
  }
)

// Error response
return responses.error(
  {
    code: 'VALIDATION_ERROR',
    message: 'Invalid email address',
    field: 'email',
  },
  400
)

// Not found
return responses.notFound({
  resource: 'user',
  id: '123',
})

Core Capabilities

  • Status Helpers - Pre-built helpers for common status codes
  • Content Negotiation - Automatic JSON/XML/HTML formatting
  • Error Formatting - Consistent error response structure
  • Header Management - Automatic CORS, caching headers
  • Type Safety - TypeScript types for response schemas

Access Methods

SDK

TypeScript/JavaScript library for response formatting

responses.ok({ user: { id: '123', name: 'Alice' } })

SDK Documentation

CLI

Command-line tool for response testing

do response format --status 200 --data '{"user":{"id":"123"}}'

CLI Documentation

API

REST/RPC endpoints return formatted responses

API Documentation

MCP

Model Context Protocol with formatted responses

All MCP responses use the responses primitive for consistent formatting

MCP Documentation