技术原理
¥Technical Principles
Fastify 框架及其官方插件中的每一个决定都遵循以下技术原则:
¥Every decision in the Fastify framework and its official plugins is guided by the following technical principles:
-
生产中“零”开销
¥“Zero” overhead in production
-
“良好”的开发者体验
¥“Good” developer experience
-
非常适合小型和大型项目
¥Works great for small & big projects alike
-
易于迁移到微服务(甚至无服务器)并返回
¥Easy to migrate to microservices (or even serverless) and back
-
安全和数据验证
¥Security & data validation
-
如果某个东西可以是插件,那么它很可能应该是
¥If something could be a plugin, it likely should be
-
易于测试
¥Easily testable
-
不要给核心打猴子补丁
¥Do not monkeypatch core
-
语义版本控制和长期支持
¥Semantic versioning & Long Term Support
-
遵守规范
¥Specification adherence
"零" 生产间接费用
¥"Zero" Overhead in Production
Fastify 旨在以最小的开销实现功能。这是通过使用快速算法、数据结构和 JavaScript 特定功能实现的。
¥Fastify aims to implement features with minimal overhead. This is achieved by using fast algorithms, data structures, and JavaScript-specific features.
由于 JavaScript 不提供零开销数据结构,因此该原则可能与提供出色的开发者体验和附加功能相冲突,因为这些通常会产生一些开销。
¥Since JavaScript does not offer zero-overhead data structures, this principle can conflict with providing a great developer experience and additional features, as these usually incur some overhead.
"良好" 开发者体验
¥"Good" Developer Experience
Fastify 旨在在其性能点上提供最佳的开发者体验。它提供了出色的开箱即用体验,足够灵活,可以适应各种情况。
¥Fastify aims to provide the best developer experience at its performance point. It offers a great out-of-the-box experience that is flexible enough to adapt to various situations.
例如,二进制插件是被禁止的,因为大多数 JavaScript 开发者无法访问编译器。
¥For example, binary addons are forbidden because most JavaScript developers do not have access to a compiler.
非常适合小型和大型项目
¥Works great for small and big projects alike
大多数应用都是从小处开始,随着时间的推移变得越来越复杂。Fastify 旨在随着这种复杂性而发展,提供高级功能来构建代码库。
¥Most applications start small and become more complex over time. Fastify aims to grow with this complexity, providing advanced features to structure codebases.
易于迁移到微服务(甚至无服务器)并返回
¥Easy to migrate to microservices (or even serverless) and back
路由部署无关紧要。框架应该 "正常工作"。
¥Route deployment should not matter. The framework should "just work".
安全和数据验证
¥Security and Data Validation
Web 框架是与不受信任的数据的第一个接触点,必须充当系统的第一道防线。
¥A web framework is the first point of contact with untrusted data and must act as the first line of defense for the system.
如果某个东西可以是一个插件,它可能应该
¥If something could be a plugin, it likely should
认识到 HTTP 框架的无限用例,在单个模块中满足所有用例将使代码库无法维护。因此,提供了钩子和选项以根据需要自定义框架。
¥Recognizing the infinite use cases for an HTTP framework, catering to all in a single module would make the codebase unmaintainable. Therefore, hooks and options are provided to customize the framework as needed.
易于测试
¥Easily testable
测试 Fastify 应用应该是首要关注的问题。
¥Testing Fastify applications should be a first-class concern.
不要给核心打猴子补丁
¥Do not monkeypatch core
Monkeypatching Node.js API 或安装改变运行时的全局变量会使构建模块化应用变得更加困难,并限制了 Fastify 的用例。其他框架也这样做;Fastify 不会。
¥Monkeypatching Node.js APIs or installing globals that alter the runtime makes building modular applications harder and limits Fastify's use cases. Other frameworks do this; Fastify does not.
语义版本控制和长期支持
¥Semantic Versioning and Long Term Support
一个清晰的 提供长期支持策略,用于通知开发者何时升级。
¥A clear Long Term Support strategy is provided to inform developers when to upgrade.
遵守规范
¥Specification adherence
带着疑问,我们选择了相关规范定义的严格行为。
¥In doubt, we chose the strict behavior as defined by the relevant Specifications.