re.js is a framework built on top of Express that facilitates the development of API endpoints using the capabilities of Typescript and Zod.
- 💥 Tiny and lightweight
- 🏆 First class support of Zod and Typescript
- 🧠 Fully-typed routes, params and output
- 🤓 Out of the box OpenAPI/Swagger support
- 😎 Backward compatible with Express
bash npm install @relab/rejs --save
import { route } from '@relab/rejs'
import { z } from 'zod'
export const helloWorld = route({
method: 'POST',
path: '/hello/:name',
schema: {
route: z.object({
name: z.coerce.string(),
}),
result: z.string(),
},
})(({ route }, context) => {
return `${route.name}, hello world!`
})
In your index.ts
:
import { serve } from '@relab/rejs'
import { helloWorld } from './hello-world'
void serve(
{
port: Number(process.env.PORT) || 3000,
routes: [
helloWorld,
],
},
port => {
logger.info(`Listening http://localhost:${port}`)
}
)
npm install @relab/rejs-swagger --save
In your index.ts
:
import { serve } from '@relab/rejs'
import { swagger } from '@relab/rejs-swagger'
import { helloWorld } from './hello-world'
void serve(
{
port: Number(process.env.PORT) || 3000,
middlewares: [
swagger({
ui: {
enabled: true,
},
}),
],
routes: [
helloWorld,
],
},
port => {
logger.info(`Listening http://localhost:${port}`)
}
)
Now you can access Swagger by /swagger
and /swagger/swagger.json
URLs.
Released under MIT by Sergey Zwezdin.