Expert guidance for micro — asynchronous HTTP microservices framework by Vercel. Use when building lightweight HTTP servers, API endpoints, or microservices using the micro library.
66
80%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
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.
npm install microCreate 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 microjson(req) — Parse JSON Bodyimport { json } from 'micro'
export default async (req: IncomingMessage, res: ServerResponse) => {
const body = await json(req)
return { received: body }
}text(req) — Parse Text Bodyimport { text } from 'micro'
export default async (req: IncomingMessage, res: ServerResponse) => {
const body = await text(req)
return `You said: ${body}`
}buffer(req) — Parse Raw Bodyimport { 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 Responseimport { send } from 'micro'
export default (req: IncomingMessage, res: ServerResponse) => {
send(res, 200, { status: 'ok' })
}createError(statusCode, message) — HTTP Errorsimport { createError } from 'micro'
export default (req: IncomingMessage, res: ServerResponse) => {
if (!req.headers.authorization) {
throw createError(401, 'Unauthorized')
}
return { authorized: true }
}micro-dev provides hot-reloading for development:
npm install --save-dev micro-dev
# Run in dev mode
npx micro-dev index.jsChain 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){
"main": "index.js",
"scripts": {
"start": "micro",
"dev": "micro-dev"
},
"dependencies": {
"micro": "^10.0.0"
},
"devDependencies": {
"micro-dev": "^3.0.0"
}
}createError() for proper status codesmicro-router for multi-route servicesjson(), text(), or buffer() to parse request bodies1e28582
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.