API Reference
Farrow provides a complete set of APIs for building type-safe web applications. This documentation provides detailed API reference for all core modules.
Core Modules
farrow-http
TypeScript-first Web Framework - Provides type-safe routing and automatic validation
- HTTP/HTTPS server creation and configuration
- Type-safe routing patterns and automatic validation
- Powerful Response builder system
- Modular router and middleware system
- Context management and error handling
- Static file serving and CORS integration
- Express integration support
farrow-schema
Powerful Type Validation and Serialization Library - Handle data easily through type-driven design
- Complete basic type system (String, Number, Boolean, Date, ID)
- Flexible composite types (List, Optional, Nullable, Record, Tuple)
- Structured type definitions (ObjectType, Struct)
- Union and intersection types (Union, Intersect, Literal)
- Schema manipulation tools (pickObject, omitObject, partial, required)
- Built-in and custom validator system
- Complete TypeScript type inference support
farrow-pipeline
Type-safe Middleware Pipeline Library - Provides functional programming style request processing
- Synchronous and asynchronous Pipeline creation
- Type-safe context management system
- Container concept and dependency injection
- Pipeline composition and middleware execution
- Utilities and error handling
- Async tracing support
Quick Navigation
HTTP Service
Core API
- HTTP Server -
Http(),Https(), configuration options - Router System -
Router(), HTTP method routing - Request & Validation -
RequestInfo, automatic validation - Response Building -
Responseobject and methods - Middleware System - Onion model, execution order
Advanced Features
- Context Management - Context system, request hooks
- Error Handling -
HttpError, global error handling - Utilities -
ParseUrl, type tools - Best Practices - Dependency injection, testing strategies
Schema Validation
Type System
- Basic Type Schemas -
String,Number,Boolean,Date,ID,Int,Float - Composite Type Schemas -
List,Optional,Nullable,Record,Tuple - Structured Type Schemas -
ObjectType,StructType,Union,Intersect,Literal - Special Type Schemas -
Any,Unknown,Never,Json
Validation & Formatting
- Validator System - Runtime data validation
- Formatter System - Type metadata extraction
- Result Type - Functional error handling
Helper Tools
- field - Field metadata definition
- pick series - Select fields
- omit series - Exclude fields
- partial series - Convert to optional
- required series - Convert to required
Pipeline System
Core Features
- Pipeline Type System -
createPipeline,createAsyncPipeline - Middleware Types -
Middleware,Next,MiddlewareInput - usePipeline - Run sub-Pipeline with inherited container
Context System
- Context System -
createContext, context methods - Container System -
createContainer, container methods - AsyncTracer - Async context propagation
API Conventions
Naming Conventions
- Types: PascalCase (e.g.,
ObjectType,HttpError) - Functions: camelCase (e.g.,
createContext,pickStruct) - Constants: UPPER_CASE (e.g.,
DEFAULT_PORT) - Files: kebab-case (e.g.,
farrow-http)
Type Annotations
All APIs include complete TypeScript type definitions:
typescript
// Function signature
function createContext<T>(defaultValue: T): Context<T>
// Type definition
type RequestInfo = {
readonly pathname: string
readonly method?: string
readonly query?: RequestQuery
readonly body?: any
readonly headers?: RequestHeaders
readonly cookies?: RequestCookies
}