| name | iii-http-middleware |
| description | 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. |
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_ids in the trigger config
- The engine executes middleware in order — first middleware runs first, then the next, then the handler
- Middleware receives a
MiddlewareFunctionInput with phase, request (path_params, query_params, headers, method), and context from 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 |
|