waiter-framework
v0.1.3
Published
High-performance web framework with IoC and decorators
Maintainers
Readme
Waiter Framework
A lightweight, TypeScript-first web framework with built-in dependency injection and decorator-based routing.
Installation
npm install waiter-frameworkQuick Start
import { bootstrapWaiter, Web, Get, WaiterRequest } from 'waiter-framework';
@Web('/api')
class UserController {
@Get('/users')
async getUsers(req: WaiterRequest) {
return {
statusCode: 200,
body: { users: [] },
};
}
}
bootstrapWaiter(3000);Features
- Decorator-based routing
- Built-in IoC container
- TypeScript support
- Interceptor/middleware system
- Zero configuration required
Dependency Injection
import { Web, Get, Inject, Wire } from 'waiter-framework';
@Wire('database')
class Database {
query(sql: string) {
// implementation
}
}
@Web('/api')
class UserController {
constructor(@Inject('database') private db: Database) {}
@Get('/users')
async getUsers() {
const users = this.db.query('SELECT * FROM users');
return { statusCode: 200, body: users };
}
}Interceptors
import {
bootstrapWaiter,
WaiterRequest,
WaiterResponse,
} from 'waiter-framework';
const authInterceptor = async (
req: WaiterRequest
): Promise<WaiterResponse | void> => {
const token = req.serverRequest.headers['authorization'];
if (!token) {
return { statusCode: 401, body: { error: 'Unauthorized' } };
}
};
bootstrapWaiter(3000, authInterceptor);HTTP Methods
@Web('/api')
class ProductController {
@Get('/products')
async list() {
/* ... */
}
@Post('/products')
async create(req: WaiterRequest) {
/* ... */
}
@Put('/products/:id')
async update(req: WaiterRequest) {
/* ... */
}
@Delete('/products/:id')
async remove(req: WaiterRequest) {
/* ... */
}
}License
MIT
