Context & Derivation
Powering your handlers with typed dependencies.
The Context (or ctx) is the soul of an Axeom handler. It contains everything you need to process a request and returned a response. But Axeom takes it one step further with Context Derivation.
The ctx Object
Every handler receives a ctx object which natively includes:
ctx.request: The standard WebRequestobject.ctx.headers: Fast access toctx.request.headers.ctx.params: Typed path parameters (e.g.,:id).ctx.query: Typed search query parameters.ctx.body: Automatically parsed JSON or FormData body.ctx.time: The request's start timestamp.
Decoration & Derivation
Axeom allows you to inject dependencies or data into your context using .decorate() and .derive().
.decorate()
Use this for static dependencies like database clients that don't change per-request.
const = new ()
.({
: new (),
: { : 'production' }
});
.("/users", () => {
// ctx.db and ctx.config are available and fully typed!
return ...();
});.derive()
Use this for per-request computations, like extracting authenticated users.
const =
.(async ({ }) => {
const = .("x-user-id");
if (!) return { : null };
return {
: { : , : 'admin' }
};
});
.("/me", () => {
return .; // ctx.user was derived per-request
});Performance: Mutation-Free Selection
Axeom is designed for massive throughput. Instead of complex object spreading, it uses a high-performance context pool and deterministic property injection.
- Lower Memory Pressure: Minimal object allocation during derivation.
- Higher Throughput: Optimized for modern JIT engines by maintaining stable object shapes.
- Perfect Types: Your IDE always knows exactly which properties are available based on your
.derive()and.decorate()chain.
Group Isolation
When you use .group(), it creates a branch of the engine. Derivations added inside a group only affect routes within that group.
.("/admin", () => {
.()
.("/dashboard", () => {
// ctx.admin is available here
return "Welcome";
});
});
.("/public", () => "Always available");