Dwarves
Memo
Type ESC to close search bar

Typesafe Client Server

Motivation

In traditional software development, defining models and API clients is a fundamental step when using strongly-typed languages.

Syncing these elements between the backend and frontend is important in the software development process.However, this synchronization is often manual and error-prone, leading to inconsistencies that can cause runtime failures and bugs. To address this challenge, typesafe client-server architecture introduces a code generation layer that bridges the gap between frontend and backend more effectively.

Using API definitions in JSON or YAML format as the single source of truth, the code generator automatically validates and generates the necessary models and API clients for the frontend and corresponding models and API endpoints for the backend. This ensures that both ends of the application speak the same “data language,” and any changes in the API are reflected on both sides promptly and accurately.

This automated approach not only minimizes human error but also streamlines the development process, as developers can now focus on building features rather than fixing mismatches between the FE and BE. By adopting this typesafe client-server system, teams can enhance collaboration, accelerate time-to-market, and deliver a more reliable product.

Benefits

How to use effectively

Supported frameworks/tools

openapi-generator: Official tool to validate Swagger spec and generate clients. Using Axios for client requests. Orval: Generate code in various clients (axios, swr, react-query…). Support mock data with msw and faker

References