$ show ecyrbe/zodios
Zodios is a TypeScript library that provides a fully typed and validated REST API client built on top of axios and zod, along with a companion server adapter for Express. The core library (`@zodios/core`) offers a centralized API definition format using zod schemas, auto-complete for paths and parameters on the client side, and runtime validation of both request parameters and responses. It includes a sophisticated plugin system for intercepting requests and responses with support for named plugin replacement and per-endpoint registration. The library also provides helper functions for building API definitions (`makeApi`, `apiBuilder`, `parametersBuilder`, `makeCrudApi`, `mergeApis`) and internal plugins for form-data, form-url, and text request formats. The system is designed for end-to-end type safety, allowing developers to share API definitions between client and server code. It has been well-architected with a clean separation of concerns: the client class (`Zodios`) handles HTTP communication through axios and delegates schema validation to the validation plugin, while the API definition helpers provide a builder pattern for composing endpoints. The plugin system is particularly notable for its flexible registration (global, by alias, or by method+path) and its correct reverse-order execution for response interceptors. Overall, the codebase demonstrates strong TypeScript craftsmanship, disciplined use of type inference and utility types (e.g., path parameter extraction at the type level), and a modular design that allows features like CRUD generation and API merging. While not revolutionary, it is a solid, production-quality library that effectively solves the problem of type-safe REST communication.
The LLM identified 3 files worth highlighting for reuse:
Implements a plugin registry (`ZodiosPlugins`) that stores an ordered list of plugins per endpoint (or globally). Supports named plugins for replacement, provides `use` and `eject` methods, and orchestrates request/response/error interceptors. Response interceptors are executed in reverse registration order, which is correct for middleware pipelines. This component is self-contained and demonstrates a clean, testable pattern for managing interceptors in any HTTP client library.
Contains advanced TypeScript utility types used throughout the library, such as `FilterArrayByValue`, `FilterArrayByKey`, `Narrow`, `PathParamNames`, `MergeUnion`, and `SplitMany`. These types enable type-level operations on arrays and strings, particularly for extracting path parameter names from URL patterns. They are generic and could be extracted and reused in any TypeScript project requiring sophisticated type manipulation.
Provides the public API for constructing endpoint definitions: `makeApi`, `apiBuilder`, `parametersBuilder`, `makeCrudApi`, `prefixApi`, and `mergeApis`. The `apiBuilder` class allows fluent chaining of endpoints with proper type inference. `parametersBuilder` similarly provides a type-safe way to build parameters using methods like `addQueries`, `addHeaders`, etc. `makeCrudApi` auto-generates standard CRUD endpoints from a resource name and zod schema. These builders are well-encapsulated and can be extracted as standalone patterns for any API definition system.