asterflow
v0.0.6
Published
<div align="center">
Readme
Asterflow
The heart of the AsterFlow framework, providing server initialization and configuration with strong typing.
📦 Installation
npm install asterflow
# or
bun install asterflow💡 About
Asterflow is the central package of the AsterFlow framework. It provides server initialization, integration with different HTTP adapters, and a typed routing system. The package brings together all other AsterFlow components into a cohesive framework.
✨ Features
- HTTP Adapters: Native support for different HTTP servers (Node.js, Fastify, Express)
- Routing System: Typed routing with support for dynamic parameters
- Middleware: Flexible middleware system with typed context
- Type Safety: Full TypeScript support with type inference
- High Performance: Optimized routing system using prefix tree (trie)
- URL Analysis: Integrated URL parser with support for dynamic parameters
🚀 Usage
Basic Setup
import { AsterFlow } from 'asterflow'
import { adapters } from '@asterflow/adapter'
import fastify from 'fastify'
const server = fastify()
const aster = new AsterFlow({
driver: adapters.fastify
})
aster.listen(server, { port: 3000 })Defining Routes
import { Router } from '@asterflow/router'
const router = new Router({
path: '/:id=number?query#fragment',
methods: {
get({ response, url }) {
const params = url.getParams() // params.id is typed as number
const query = url.getSearchParams()
return response.send('Hello World')
}
}
})
aster.controller(router)Using Middleware
import { Middleware, Router } from '@asterflow/router'
const auth = new Middleware({
name: 'auth',
onRun({ next }) {
return next({
auth: false
})
}
})
const router = new Router({
path: '/protected',
use: [auth],
methods: {
get({ response, middleware }) {
if (!middleware.auth) {
return response.unauthorized({
message: 'Unauthorized'
})
}
return response.send('Protected area')
}
}
})Individual Routes
import { Method } from '@asterflow/router'
const route = new Method({
path: '/users/:id=number',
method: 'get',
handler: ({ response, url }) => {
const { id } = url.getParams() // id is typed as number
return response.send({ id })
}
})
aster.controller(route)🔗 Related Packages
- @asterflow/adapter - HTTP adapters for different runtimes
- @asterflow/router - Type-safe routing system
- @asterflow/request - Unified HTTP request system
- @asterflow/response - Type-safe HTTP response system
- reminist - Blazing fast, zero-dependency, TypeScript-native router
- @asterflow/url-parser - High-performance typed URL parser with automatic type casting
- @asterflow/plugin - A modular and typed plugin system
📄 License
MIT - See LICENSE for more details.
