xPulse
πŸ‡¬πŸ‡§ EN

@xpulse/http – Component Spec

Status: CONCEPT Β· Created March 2026 Parent: GLOBAL_concept-ecosystem.md, GLOBAL_concept-web.md


Overview

HTTP server for the xPulse ecosystem. Provides server, request, and response.

One responsibility: HTTP – nothing more.

Has no knowledge of routing concepts, controllers, or templates. Can be used standalone – for minimal projects without an MVC stack.


Dependencies

@xpulse/http
β”œβ”€β”€ @xpulse/event ← fire http:request, http:response
└── @xpulse/logger ← internal logging

API

Initialising

import http from '@xpulse/http';
await http.init();

env, debug, and port come from .env via @xpulse/config – http.init() takes no parameters.

Starting / Stopping

http.start(); // blocking
http.stop(); // graceful shutdown – finish in-flight requests first

Registering a route

http.route('GET', '/path', handler);
http.route('POST', '/path', handler);

Handler signature:

(req, res) => {
res.send('<h1>Hello</h1>');
}

Minimal example without MVC

import http from '@xpulse/http';
await http.init();
http.route('GET', '/', (req, res) => {
res.send('<h1>xPulse</h1>');
});
http.route('GET', '/health', (req, res) => {
res.status(200).send('ok');
});
http.start();
process.on('SIGTERM', () => http.stop());

Request API

Property / Method Description
req.method HTTP method – GET, POST
req.path URL path without query string – /tool/chat
req.params URL parameters from pattern – { id: '42' }
req.query Query string parameters – { lang: 'de' }
req.body Request body – parsed for POST
req.headers Request headers

URL Parameters Example

http.route('GET', '/tool/:tool/:page?', (req, res) => {
const { tool, page } = req.params;
// /tool/chat β†’ { tool: 'chat', page: undefined }
// /tool/chat/guide β†’ { tool: 'chat', page: 'guide' }
res.send(`Tool: ${tool}`);
});

Query String Example

http.route('GET', '/doc', (req, res) => {
const lang = req.query.lang ?? 'de';
// /doc?lang=en β†’ lang = 'en'
res.send(`Lang: ${lang}`);
});

Response API

Method Description
res.send(html) Send HTML, status 200
res.status(code) Set status code, returns res (chainable)
res.header(name, value) Set response header, returns res (chainable)

Chaining Example

res.status(404).send('<h1>Not found</h1>');
res.status(301).header('Location', '/new').send('');

Emitted Events

Event Payload When
http:request { method, path, params, query } on every incoming request
http:response { method, path, status, duration } after every response sent
import event from '@xpulse/event';
event.on('http:request', ({ method, path }) => {
// automatically logged by @xpulse/logger
});

.env Configuration

Variable Default Description
PORT 3000 Server port
HOST 0.0.0.0 Server host

Debug Integration

When @xpulse/debug is installed as a devDependency, @xpulse/http automatically provides a DataCollector. @xpulse/debug discovers it via node_modules/@xpulse/http/src/datacollectors/ – no configuration needed.

"optionalDependencies": {
"@xpulse/debug": "^1.0.0"
}

The HttpCollector (name: 'http', icon: '🌐') shows in the Web Profiler:

In addition the HttpCollector writes a Waterfall Span (kind: 'http') that represents the total request duration – the widest bar in the waterfall.

Badge in the toolbar: 200 Β· 12ms


Package Structure

@xpulse/http/
src/
index.js ← default export: http object
server.js ← Node http.createServer wrapper
request.js ← request wrapper
response.js ← response wrapper
test/
http.test.js
request.test.js
response.test.js
docs/
index.md
api.md
_meta.json
Dockerfile
Makefile
README.md
package.json
xpulse.json
en/spec.md 2026-03-27