DEV Community

Rs. Rimon
Rs. Rimon

Posted on

Simplify AWS Lambda Routing with Zapix – A Lightweight TypeScript Router

If you’re building serverless applications on AWS Lambda, handling routing, middleware, and errors can quickly get messy. Enter Zapix – a lightweight, TypeScript-friendly router designed specifically for Lambda.

Why Zapix?

  • Minimal router supporting get, post, put, patch, delete, options, and all methods
  • Middleware chaining similar to Express.js – validate, authenticate, or transform requests easily
  • Global error handling with router.useError for centralized control
  • Safe and consistent HTTP responses with the Response() utility
  • Fully typed for TypeScript, providing IntelliSense and safer code

Key Features

  1. Middleware & Handlers – chain multiple middlewares before hitting your main controller.
  2. Centralized Error Handling – catch validation errors, JS errors, and more in one place.
  3. Type Safety – request and response objects are strongly typed.
  4. UtilitiessafeJsonParse for JSON safety and Response() for unified responses.

Getting Started

Install Zapix via npm:

npm install zapix
Enter fullscreen mode Exit fullscreen mode

Example usage:

import { Router, Handler } from 'zapix';

const router = new Router();

router.post('/users', createUser);
router.get('/users', readUsers);
router.get('/users/{userId}', readUserInfo);
router.put('/users/{userId}', updateUser);
router.delete('/users/{userId}', deleteUser);

// Fallback route
router.all(() => ({
  statusCode: 404,
  body: JSON.stringify({ error: 'Route not found' }),
}));

export const handler = Handler(router);
Enter fullscreen mode Exit fullscreen mode

Zapix makes it simple to write clean, maintainable Lambda functions without losing type safety or flexibility.

Try it out

Check out the repo and documentation here: https://www.npmjs.com/package/zapix

Tags: #AWS #Serverless #AWSLambda #TypeScript #NodeJS #WebDevelopment #OpenSource #DeveloperTools

Top comments (0)