micro
SKILL.md
micro — Asynchronous HTTP Microservices
You are an expert in micro, Vercel's lightweight framework for building asynchronous HTTP microservices in Node.js. micro makes it easy to write single-purpose HTTP endpoints with minimal boilerplate.
Installation
npm install micro
Basic Usage
Create a module that exports a request handler:
// index.ts
import { serve } from 'micro'
const handler = (req: Request) => {
return new Response('Hello, World!')
}
serve(handler)
Or use the classic API:
import { IncomingMessage, ServerResponse } from 'http'
export default (req: IncomingMessage, res: ServerResponse) => {
res.end('Hello, World!')
}
Run with:
npx micro
Core API
json(req) — Parse JSON Body
import { json } from 'micro'
export default async (req: IncomingMessage, res: ServerResponse) => {
const body = await json(req)
return { received: body }
}
text(req) — Parse Text Body
import { text } from 'micro'
export default async (req: IncomingMessage, res: ServerResponse) => {
const body = await text(req)
return `You said: ${body}`
}
buffer(req) — Parse Raw Body
import { buffer } from 'micro'
export default async (req: IncomingMessage, res: ServerResponse) => {
const raw = await buffer(req)
return `Received ${raw.length} bytes`
}
send(res, statusCode, data) — Send Response
import { send } from 'micro'
export default (req: IncomingMessage, res: ServerResponse) => {
send(res, 200, { status: 'ok' })
}
createError(statusCode, message) — HTTP Errors
import { createError } from 'micro'
export default (req: IncomingMessage, res: ServerResponse) => {
if (!req.headers.authorization) {
throw createError(401, 'Unauthorized')
}
return { authorized: true }
}
Development with micro-dev
micro-dev provides hot-reloading for development:
npm install --save-dev micro-dev
# Run in dev mode
npx micro-dev index.js
Composition
Chain multiple handlers with function composition:
import { IncomingMessage, ServerResponse } from 'http'
const cors = (fn: Function) => async (req: IncomingMessage, res: ServerResponse) => {
res.setHeader('Access-Control-Allow-Origin', '*')
return fn(req, res)
}
const handler = async (req: IncomingMessage, res: ServerResponse) => {
return { hello: 'world' }
}
export default cors(handler)
package.json Setup
{
"main": "index.js",
"scripts": {
"start": "micro",
"dev": "micro-dev"
},
"dependencies": {
"micro": "^10.0.0"
},
"devDependencies": {
"micro-dev": "^3.0.0"
}
}
Key Points
- Return values are sent as responses — return strings, objects (auto-serialized to JSON), or Buffers
- Async by default — handlers can be async functions, errors are caught automatically
- Thrown errors become HTTP errors — use
createError()for proper status codes - No routing built-in — micro is a single-endpoint server; use a router like
micro-routerfor multi-route services - Body parsing is explicit — use
json(),text(), orbuffer()to parse request bodies - Composable — wrap handlers with higher-order functions for middleware-like behavior
Official Resources
Weekly Installs
4
Repository
vercel-labs/ver…l-pluginGitHub Stars
7
First Seen
9 days ago
Security Audits
Installed on
opencode4
mcpjam3
claude-code3
junie3
windsurf3
zencoder3