hyperin
v0.1.0
Published
π Fast, safe and modern
Downloads
1,155
Readme
Installation
This is a Node.js module available through the npm registry.
npm install hyperinFeatures
- Fast radix-tree routing
- Middleware pipeline with
next() - Built-in JSON, cookies, compression, CORS, security, multipart, and static file helpers
- Typed request and response primitives
- Express-like settings API
- OpenAPI and Scalar support
Quick Start
import { hyperin } from 'hyperin'
import { json } from 'hyperin/middleware'
const app = hyperin()
app.use(json())
app.get('/', () => ({ message: 'Hello World' }))
app.post('/users', ({ request, response }) => {
response.status(201)
return {
created: true,
body: request.body
}
})
app.listen(3000, () => {
console.log('Server running at http://localhost:3000')
})Validation
Route methods accept multiple handlers. Pass the route options object as the last argument to add validation and documentation metadata.
import { hyperin } from 'hyperin'
import { json } from 'hyperin/middleware'
import { z } from 'zod'
const app = hyperin()
app.use(json())
app.post(
'/login',
({ request, response }) => {
const { email, password } = request.body
response.status(201)
return { email, password }
},
{
body: z.object({
email: z.email(),
password: z.string().min(6)
})
}
)Hyperin also supports Standard Schema, allowing you to use your favorite validation library.
Supported Standard Schema libraries include:
Logger
Use the built-in logger to emit structured events with custom levels, metadata, and async transports.
import { hyperin } from 'hyperin'
import { createLogger } from 'hyperin/logger'
const app = hyperin()
const logger = createLogger({
kind: 'audit',
level: 'info',
transports: [
async function ({ event }) {
console.log(event)
}
]
})
app.get('/', async function () {
logger.trace('Get all the data.', {})
return {
message: 'Hello, World!'
}
})
app.listen(7000, '0.0.0.0')OpenAPI
Generate an OpenAPI document from route schemas.
import { openapi } from 'hyperin/openapi'
openapi(app, {
documentation: {
info: {
title: 'My API',
version: '1.0.0'
}
}
})The document is available at GET /openapi.json by default.
Scalar
Expose a Scalar UI for the generated OpenAPI document.
import { scalar } from 'hyperin/scalar'
scalar(app)
scalar(app, {
path: '/docs',
url: '/openapi.json',
configuration: {
theme: 'purple',
layout: 'modern'
}
})Documentation
Full documentation is being prepared. For now, the codebase and tests are the best reference for the public API.
Contributing
npm install
npm test
npm run buildIssues and pull requests are welcome.
Support
Enjoying this framework? Consider supporting the project.
