handlers

Handle HTTP requests and format API responses for Bun/TypeScript REST endpoints.

Updated Apr 16, 2025
One-click install
npx skills add https://github.com/teexiii/boilerplate-rest-bun-for-noob --skill handlers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: handlers
Source: https://github.com/teexiii/boilerplate-rest-bun-for-noob/tree/main/.agent/skills/handlers
Command: npx skills add https://github.com/teexiii/boilerplate-rest-bun-for-noob --skill handlers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a consistent pattern for processing HTTP requests and producing standardized API responses, reducing duplicated error handling and inconsistent response shapes across a codebase.

Core Features & Use Cases

  • Unified Error Handling: Enforce wrapping handler logic with an errorHandler wrapper that catches JSON parsing issues, service errors, and Prisma-specific errors and maps them to proper HTTP statuses.
  • Request Parsing & Validation: Demonstrates reliable parsing of JSON bodies, route parameters, and query parameters, with examples for authentication checks and input validation for common CRUD operations.
  • Response Formatting & Mapping: Supplies success and failure helper patterns to return consistent payloads and shows mapper usage to transform service models into API responses; ideal for REST endpoints like user, baby, and activity resources.

Quick Start

Wrap your handler logic in the errorHandler wrapper, parse the request body or params as shown, perform service operations, and return results using the success or fail helpers.

Frequently Asked Questions about handlers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize API responses and handle errors in a Bun TypeScript server?

You can standardize API responses by wrapping handler logic in an errorHandler wrapper and using success or fail helpers. This pattern catches JSON parsing issues and service errors, mapping them to consistent HTTP statuses and payloads for Bun TypeScript servers.

What is the best way to handle Prisma errors in HTTP REST endpoints?

Handling Prisma errors in REST endpoints involves using an errorHandler wrapper that catches Prisma-specific exceptions. The wrapper maps these database errors to proper HTTP statuses, ensuring consistent failure responses across your API.

How do I parse JSON bodies and route parameters for CRUD operations in Bun?

Parsing JSON bodies and route parameters in Bun requires reliable extraction logic within your HTTP handler. You can then perform input validation and authentication checks before executing service operations for your CRUD endpoints.

How do I use mappers to transform service models into API responses?

Using mappers to transform service models into API responses involves applying mapper-based transformation before returning data. This ensures your REST endpoints output consistent payload shapes separate from internal database models.

Can I use this handler pattern for authentication checks and query parameters?

Yes, this handler pattern supports parsing query parameters and enforcing authentication checks. It provides examples for validating inputs and securing common CRUD operations within your Bun TypeScript server environment.