Micri Microservices Framework

4.5.1 · active · verified Tue Apr 21

Micri is a lightweight, asynchronous HTTP microservices library for Node.js, currently at version 4.5.1. It provides a minimal yet high-performance foundation for building single-purpose HTTP functions, emphasizing explicit control over request handling. Key differentiators include its small codebase (~500 lines), opt-in JSON parsing for speed, and strong integration with `async`/`await` patterns for easy asynchronous operations. Unlike larger frameworks, Micri deliberately avoids middleware, requiring developers to explicitly declare and handle all dependencies within their request handlers. Its standard HTTP approach and agility make it suitable for containerized and serverless deployments. The project has a stable release cadence, with recent major updates addressing Node.js compatibility and core feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a basic Micri HTTP server using the `serve` function, handling an asynchronous request, and listening on a specified port. It highlights Micri's `async`/`await` focus for simple handlers.

import { serve } from 'micri';
import { ServerResponse, IncomingMessage, Server } from 'http';

const sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms));

interface CustomRequest extends IncomingMessage {
  // Micri handlers receive native Node.js http.IncomingMessage
  // You can extend it for custom properties if needed.
}

const handler = async (req: CustomRequest, res: ServerResponse): Promise<string> => {
  // Simulate an asynchronous operation, e.g., database call or external API fetch
  await sleep(500);
  
  // Micri handlers can return a string, Buffer, or Stream directly to send as the response body.
  return `Hello from Micri! You accessed: ${req.url}`;
};

const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
const server: Server = serve(handler);

server.listen(PORT, () => {
  console.log(`Micri server listening on http://localhost:${PORT}`);
  console.log('Try opening http://localhost:3000/hello or http://localhost:3000/world in your browser.');
});

view raw JSON →