data(context)
data() is the main function form for route modules.
Use it when:
- the route payload is computed
- you need
params - you want to fetch remote data at build time
Supported forms
StatikAPI accepts either:
export default { hello: 'world' };
or:
export async function data(context) {
return { hello: 'world' };
}
It also accepts:
export default async function data(context) {
return { hello: 'world' };
}
What context currently contains
Regular CLI path
For the normal statikapi build / statikapi dev path, context currently includes:
params- dynamic/catch-all params when applicable
__fresh- internal dev-only freshness flag during rebuilds
Examples:
- static route:
{}
- dynamic route
/users/1:{ params: { id: '1' } }
- catch-all route
/docs/api/intro:{ params: { slug: ['api', 'intro'] } }
Cloudflare adapter path
For the Cloudflare adapter, route execution currently receives:
paramsenv
where env is the Worker environment/bindings object.
So if you write code that depends on env, that is Cloudflare-specific behavior, not the generic local CLI contract.
Example
export async function data({ params }) {
return {
id: params.id,
role: 'member',
};
}
Rules
data() must return JSON-serializable output.
Allowed:
- strings
- booleans
- finite numbers
null- plain objects
- arrays
Rejected:
DateBigInt- functions
- class instances
- circular references
If serialization fails, the route build fails with an explicit error.