Agent skill
iii-http-middleware
Registers engine-level middleware functions that run before HTTP handlers. Use when adding authentication, request logging, rate limiting, or any pre-handler logic to HTTP endpoints.
Install this agent skill to your Project
npx add-skill https://github.com/iii-hq/iii/tree/main/skills/iii-http-middleware
SKILL.md
HTTP Middleware
Comparable to: Express middleware, Fastify hooks, Django middleware
Key Concepts
Use the concepts below when they fit the task. Not every middleware setup needs all of them.
- Middleware functions are registered like normal functions but return
{ action: 'continue' }or{ action: 'respond', response }instead of a normal response - Middleware is attached to HTTP triggers via
middleware_function_idsin the trigger config - The engine executes middleware in order — first middleware runs first, then the next, then the handler
- Middleware receives a
MiddlewareFunctionInputwithphase,request(path_params, query_params, headers, method), andcontextfrom auth - Returning
{ action: 'respond' }short-circuits the chain — the handler never runs - Returning
{ action: 'continue' }passes to the next middleware or the handler
Architecture
HTTP request
→ iii-http (port 3111)
→ Middleware 1 (continue / respond)
→ Middleware 2 (continue / respond)
→ registerFunction handler
→ { status_code, body, headers } response
iii Primitives Used
| Primitive | Purpose |
|---|---|
registerFunction(id, handler) |
Define a middleware function |
registerTrigger({ config: { middleware_function_ids } }) |
Attach middleware to an HTTP trigger |
{ action: 'continue' } |
Pass to next middleware or handler |
{ action: 'respond', response: { status_code, body } } |
Short-circuit and return response immediately |
req.request.headers |
Access request headers in middleware |
req.context |
Access auth context from RBAC auth function |
Reference Implementation
See ../references/http-middleware.js for the full working example — auth and logging middleware protecting HTTP endpoints.
Common Patterns
Code using this pattern commonly includes, when relevant:
iii.registerFunction('middleware::auth', async (req) => { ... })— auth middleware checking headersiii.registerFunction('middleware::rate-limit', async (req) => { ... })— rate limiting middlewareiii.registerFunction('middleware::request-logger', async (req) => { ... })— request loggingreq.request?.headers?.authorization— reading auth tokensreturn { action: 'respond', response: { status_code: 401, body: { error: 'Unauthorized' } } }— reject requestreturn { action: 'continue' }— allow request throughconfig: { middleware_function_ids: ['middleware::auth', 'middleware::logger'] }— attach to trigger
Adapting This Pattern
Use the adaptations below when they apply to the task.
- Chain multiple middleware for layered concerns (logging before auth before rate-limiting)
- Use middleware for cross-cutting concerns shared across multiple endpoints
- Combine with RBAC auth functions for role-based access control — auth context flows to middleware via
req.context - Keep middleware functions focused on one concern each for reusability
Pattern Boundaries
- If the task is just exposing HTTP endpoints without middleware, prefer
iii-http-endpoints. - If auth needs are complex (RBAC with function discovery control), combine this with RBAC worker auth functions.
- Stay with
iii-http-middlewarewhen the primary need is pre-handler processing for HTTP routes.
When to Use
- Use this skill when the task is primarily about
iii-http-middlewarein the iii engine. - Triggers when the request directly asks for this pattern or an equivalent implementation.
Boundaries
- Never use this skill as a generic fallback for unrelated tasks.
- You must not apply this skill when a more specific iii skill is a better fit.
- Always verify environment and safety constraints before applying examples from this skill.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
iii-dead-letter-queues
Inspects and redrives jobs that exhausted all retries. Use when handling failed queue jobs, debugging processing errors, or implementing retry strategies.
iii-cron-scheduling
Registers cron triggers with 7-field expressions to run functions on recurring schedules. Use when scheduling periodic jobs, timed automation, crontab replacements, cleanup routines, report generation, health checks, batch processing, or any task that should run every N seconds, minutes, hours, or on a weekly/monthly calendar.
iii-http-invoked-functions
Registers external HTTP endpoints as iii functions using registerFunction(id, HttpInvocationConfig). Use when adapting legacy APIs, third-party webhooks, or immutable services into triggerable iii functions, especially when prompts ask for endpoint maps like { path, id } iterated into registerFunction calls.
iii-channels
Binary streaming between workers via channels. Use when building data pipelines, file transfers, streaming responses, or any pattern requiring binary data transfer between functions.
iii-event-driven-cqrs
Implements CQRS with event sourcing on the iii engine. Use when building command/query separation, event-sourced systems, or fan-out architectures where commands publish domain events and multiple read model projections subscribe independently.
iii-agentic-backend
Creates and orchestrates multi-agent pipelines on the iii engine. Use when building AI agent collaboration, agent orchestration, research/review/synthesis chains, or any system where specialized agents hand off work through queues and shared state.
Didn't find tool you were looking for?