Core Concepts
Response System
Netpress has a smart response layer so controllers can stay simple.
A route handler can return a value, and Netpress will turn that value into the correct HTTP response when possible.
Common Response Styles
Response Helpers
The starter decorates res with helpers like:
res.success(data, meta?)res.error(message, status?, errors?)res.paginate(items, total, page, perPage)res.render(componentOrName, props, status?)
Example:
async index(_req, res) {
return res.success([{ id: 1, name: 'Amina' }]);
}
Response Builders
Netpress also exports explicit builders:
json(data, status?)view(component, props?)redirect(path)
Example:
import { json, redirect } from '@admicaa/netpress';
return json({ ok: true }, 201);
return redirect('/login');
Plain Return Values
If a handler returns a plain object or array, Netpress will serialize it as JSON.
async health() {
return { status: 'ok' };
}
Why This Helps
- Controllers need less boilerplate.
- Return types stay predictable.
- Teams can standardize response style across the app.
Recommended Pattern
Use one of these approaches consistently:
res.success()/res.error()for API-heavy appsjson()/redirect()/view()when you want explicit intent- plain returned objects for very small handlers
Consistency matters more than the specific choice.