express-cargo
Express.js를 위한 선언적 데코레이터 기반 요청 데이터 처리.
import express from 'express'
import { body, bindingCargo, getCargo, min, header, params } from 'express-cargo'
const app = express()
app.use(express.json())
class RequestExample {
@body()
name!: string
@body()
@min(0)
age!: number
@params('id')
id!: number
@header()
authorization!: string
}
app.post('/:id', bindingCargo(RequestExample), (req, res) => {
const data = getCargo<RequestExample>(req)
// write your code with bound data
})
app.listen(3000)
선언적 데이터 바인딩
직관적인 데코레이터를 활용해 요청 데이터(본문, 쿼리, 매개변수)를 클래스 인스턴스에 손쉽게 바인딩하여, 깔끔하고 응집력 있는 라우팅 로직을 구축할 수 있습니다.
강력한 데이터 유효성 검사
다양한 내장 데코레이터로 데이터 유효성을 간편하게 검사하고, 데이터를 처리하기 전에 무결성을 보장할 수 있습니다.
타입 안전성 및 확장성
TypeScript 기반으로 개발되어 완벽한 타입 안전성을 제공하며, 커스텀 데코레이터와 트랜스포머를 통해 라이브러리를 자유롭게 확장할 수 있습니다.