xPulse
πŸ‡¬πŸ‡§ EN

API

init()

await router.init();

Registers all known routes with @xpulse/http.

register(method, path, handler, name = null, namePrefix = null, pathPrefix = null)

router.register('GET', '/info', handler);
router.register('GET', '/info/:page?', handler);

Optional with default params (legacy signature):

router.register('GET', '/tool/:tool/:page?', handler, { tool: 'chat', page: 'guide' });

Compatibility note: If the 4th argument is an object and namePrefix/pathPrefix are not provided, it is treated as legacy defaults. For named/prefixed routes, use the new signature.

Optional with name and prefixes:

router.register('GET', '/info', handler, 'info.index', 'app', null);
router.register('GET', '/web-profiler/:traceId/dashboard/', handler, 'web-profiler.traceId.dashboard', 'debug', '/_debug');

Prefixes

By default, auto-generated route names start with app. and do not include the HTTP method. You can override the default prefixes via xpulse.json:

{
"router": {
"name-prefix": "app",
"path-prefix": ""
}
}

You can also set prefixes per package via register(...):

router.register('GET', '/web-profiler/:traceId/dashboard/', handler, 'web-profiler.traceId.dashboard', 'debug', '/_debug');

notFound(handler)

router.notFound((req, res) => {
res.status(404).send('Not found');
});

getPath(pattern, params)

const path = router.getPath('/tool/:tool/:page?', { tool: 'chat' });
// -> /tool/chat/guide/ (defaults apply)

list()

const routes = router.list();
// {
// 'info.index': { name, method, path, handler, defaults }
// }

Events

en/api.md 2026-03-19