Overview
The@apisr/api-aggregator package provides utilities for aggregating and orchestrating multiple API endpoints into a cohesive configuration. It includes type-safe endpoint definitions, schema validation, and HTTP client integration using ky.
Installation
Exports
The package exports the following functions and types:aggregate(config: Config)- Main aggregation functionendpoint()- Helper for defining type-safe endpoints- Type exports:
Config,Endpoint,Methods,ResponseStatus,ProbeFactory
Core Concepts
Endpoint Definition
Endpoints are the building blocks of your API configuration. Each endpoint defines:- Path: The URL path (supports params like
:id) - Method: HTTP method (GET, POST, PUT, DELETE, PATCH, OPTIONS)
- Schemas: Request/response validation schemas
- Probes: Test data for different response scenarios
Configuration
TheConfig interface defines the overall API setup:
Usage
Defining Endpoints
Use theendpoint() helper to create type-safe endpoint definitions:
Creating API Configuration
Using Probes for Testing
Probes allow you to define test data for different response scenarios:Advanced: Factory Functions
For dynamic test data, use probe factories:Type Utilities
Automatic Path Parameter Extraction
The package automatically extracts typed path parameters from endpoint paths:HTTP Methods
Supported HTTP methods:GET
Retrieve resources
POST
Create resources
PUT
Replace resources
PATCH
Update resources
DELETE
Remove resources
OPTIONS
Get supported methods
Response Status Codes
Currently supports defining probes for:200- Success400- Bad Request- Custom status codes (as strings or numbers)
Related Packages
@apisr/zod
Extended Zod validation with request source mapping
@apisr/schema
Core schema types and utilities