![](/style/images/good.png)
![](/style/images/bad.png)
GitHub - zephyr-js/zephyr: Express TS meta framework that designed with develope...
source link: https://github.com/zephyr-js/zephyr
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Zephyr.js
Build Typesafe Node API in minutes
Description
Zephyr is a Typescript server-side meta framework that is inspired by Next.js for its file-based routing. It is built on top of Express.js and uses Zod in request / response validation as well as providing typesafe API.
Zephyr places a high value on FP (Functional Programming). Instead of using classes as API controllers, declare and export API routes with functions.
Philosophy
The established server-side web frameworks for Node.js at the moment are Nest.js and Adonis.js, both of which are fantastic and rely on controllers and decorators in OOP. However, some programmers prefer functional programming to object-oriented programming (OOP). As a result, Zephyr seeks to let programmers to define API routes with functions and provides file-based routing out of the box.
Getting started
Kindly visit our documentation on zephyrjs.com
Overview
Bootstrapping Project
npm create zephyr-app <app-name>
yarn create zephyr-app <app-name>
pnpm create zephyr-app <app-name>
Defining API Route
// src/routes/login.ts
import { defineRoute } from '@zephyr-js/core';
// POST /login
export function POST() {
return defineRoute({
schema: z.object({
body: z.object({
email: z.string(),
password: z.string(),
}),
response: z.object({
success: z.boolean(),
}),
}),
onRequest(req) {
logger.info('Request received', req.method, req.path);
},
async handler({ body }) {
await login(body);
return { success: true };
},
onErrorCaptured(req, res, err) {
logger.error('Login failed', err);
res.status(500);
return { success: false };
},
});
}
- Complete
create-zephyr-app
- Publish
@zephyr-js/core
,@zephyr-js/common
andcreate-zephyr-app
to NPM - Create unit tests
- Supports dependency injection
- Create
zephyr
cli
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK