@boo-labs/server 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -67
  3. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Beltran Rodriguez Victor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,12 +1,8 @@
1
1
  # @boo-labs/server
2
2
 
3
- A lightweight, zero-dependency HTTP server for Node.js, designed around
4
- modular architecture, explicit configuration, and a predictable request
5
- lifecycle.
3
+ A lightweight, zero-dependency HTTP server for Node.js, designed around modular architecture, explicit configuration, and a predictable request lifecycle.
6
4
 
7
- `@boo-labs/server` provides a small public API for building HTTP applications
8
- with support for HTTP/1.1, HTTPS, and HTTP/2, along with routing,
9
- middleware composition, lifecycle events, and graceful resource management.
5
+ `@boo-labs/server` provides a small public API for building HTTP applications with support for HTTP/1.1, HTTPS, and HTTP/2, along with routing, middleware composition, lifecycle events, and graceful resource management.
10
6
 
11
7
  ## Features
12
8
 
@@ -45,14 +41,14 @@ TypeScript declarations for the public API are included in the package.
45
41
  ```js
46
42
  import Server, { HttpServerConfiguration } from '@boo-labs/server';
47
43
 
48
- const server = new Server(
49
- new HttpServerConfiguration({
50
- listen: {
51
- host: '127.0.0.1',
52
- port: 3000,
53
- },
54
- }),
55
- );
44
+ const configuration = new HttpServerConfiguration({
45
+ listen: {
46
+ host: '127.0.0.1',
47
+ port: 3000,
48
+ },
49
+ });
50
+
51
+ const server = new Server(configuration);
56
52
 
57
53
  server.get('/hello', (exchange) => {
58
54
  exchange.response.json({ message: 'Hello, World!' });
@@ -73,12 +69,9 @@ await server.listen();
73
69
 
74
70
  ### Exchange
75
71
 
76
- An `Exchange` represents a single HTTP transaction. It couples the incoming
77
- request with its outgoing response and exposes shared per-request state,
78
- correlation identifiers, and a cancellation signal.
72
+ An `Exchange` represents a single HTTP transaction. It couples the incoming request with its outgoing response and exposes shared per-request state, correlation identifiers, and a cancellation signal.
79
73
 
80
- Exchanges are created by the runtime and passed to middleware and handlers.
81
- Consumers do not construct exchanges.
74
+ Exchanges are created by the runtime and passed to middleware and handlers. Consumers do not construct exchanges.
82
75
 
83
76
  ```js
84
77
  server.get('/hello', async (exchange) => {
@@ -86,8 +79,17 @@ server.get('/hello', async (exchange) => {
86
79
  });
87
80
  ```
88
81
 
89
- Key properties: `id`, `traceId`, `spanId`, `signal`, `request`, `response`,
90
- and `state` (a mutable plain object for request-scoped data).
82
+ Key properties:
83
+
84
+ | Property | Type | Description |
85
+ |-------------|---------------------------|------------------------------------------|
86
+ | `id` | `string` | Unique identifier for the exchange. |
87
+ | `traceId` | `string` | W3C trace identifier. |
88
+ | `spanId` | `string` | W3C span identifier. |
89
+ | `signal` | `AbortSignal` | Cancellation signal for the exchange. |
90
+ | `request` | `Request` | Incoming request. |
91
+ | `response` | `Response` | Outgoing response. |
92
+ | `state` | `Record<string, unknown>` | Mutable per-request state. |
91
93
 
92
94
  ### Request
93
95
 
@@ -103,26 +105,31 @@ Supported media types for `body()`:
103
105
  | `application/x-www-form-urlencoded` | Parsed key/value object |
104
106
  | `multipart/form-data` | Parsed multipart representation |
105
107
 
106
- Unsupported media types raise `RequestError`. When the body exceeds the
107
- configured limit, reading fails with `RequestError` and the connection may
108
- be closed without a normal error response.
108
+ Unsupported media types raise `RequestError`. When the body exceeds the configured limit, reading fails with `RequestError` and the connection may be closed without a normal error response.
109
109
 
110
110
  The `CONNECT` method is not supported.
111
111
 
112
112
  ### Response
113
113
 
114
- Built progressively by configuring status, headers, and body. Body methods
115
- do not send anything; only `end()` materializes and sends the response.
116
- A response can describe at most one body.
114
+ Built progressively by configuring status, headers, and body. Body methods do not send anything; only `end()` materializes and sends the response. A response can describe at most one body.
117
115
 
118
- Convenience methods: `json()`, `html()`, `text()`, `send()`, `stream()`,
119
- `redirect()`, `cache()`, `noCache()`, `vary()`.
116
+ Convenience methods:
117
+
118
+ | Method | Purpose |
119
+ |--------------|--------------------------------------------------|
120
+ | `json()` | Serializes a value as JSON. |
121
+ | `html()` | Sends an HTML body. |
122
+ | `text()` | Sends a plain-text body. |
123
+ | `send()` | Sends a string or binary body. |
124
+ | `stream()` | Streams a readable body. |
125
+ | `redirect()` | Sends a redirect response. |
126
+ | `cache()` | Sets a public cache lifetime. |
127
+ | `noCache()` | Disables caching. |
128
+ | `vary()` | Adds fields to the `Vary` header. |
120
129
 
121
130
  ### Middleware
122
131
 
123
- Middleware functions receive `(exchange, next)` and run in registration
124
- order. They may be registered globally, by pathname, on a route, or on a
125
- router.
132
+ Middleware functions receive `(exchange, next)` and run in registration order. They may be registered globally, by pathname, on a route, or on a router.
126
133
 
127
134
  ```js
128
135
  server.use(async (exchange, next) => {
@@ -141,14 +148,25 @@ server.use(async (exchange, next) => {
141
148
 
142
149
  Routes associate an HTTP method and a pathname pattern with middleware.
143
150
 
144
- Supported methods: `get`, `post`, `put`, `patch`, `delete`, `head`,
145
- `trace`, `query`. Routers also support `all()`. `OPTIONS` is handled
146
- automatically.
151
+ Supported methods:
152
+
153
+ | Method | Server | Router |
154
+ |------------|--------|--------|
155
+ | `get()` | ✅ | ✅ |
156
+ | `post()` | ✅ | ✅ |
157
+ | `put()` | ✅ | ✅ |
158
+ | `patch()` | ✅ | ✅ |
159
+ | `delete()` | ✅ | ✅ |
160
+ | `head()` | ✅ | ✅ |
161
+ | `trace()` | ✅ | ✅ |
162
+ | `query()` | ✅ | ✅ |
163
+ | `all()` | ❌ | ✅ |
147
164
 
148
- Pathname patterns support literals, named parameters (`:id` or `{id}`),
149
- and wildcards (`*` / trailing `/*`). Named parameters and wildcards are
150
- used only for matching; captured values are not exposed on the exchange.
151
- To read a path segment, parse `exchange.request.pathname` directly.
165
+ **Note:** `OPTIONS` is handled automatically and does not require a dedicated registration method.
166
+
167
+ Pathname patterns support literals, named parameters (`:id` or `{id}`), and wildcards (`*` / trailing `/*`).
168
+
169
+ Named parameters and wildcards are used only for matching; captured values are not exposed on the exchange. To read a path segment, parse `exchange.request.pathname` directly.
152
170
 
153
171
  ```js
154
172
  const api = new Router();
@@ -168,15 +186,25 @@ Four configuration classes fix the transport:
168
186
  | `Http2CleartextServerConfiguration` | `http` | `h2c` |
169
187
  | `Http2SecureServerConfiguration` | `https` | `h2` |
170
188
 
171
- Common top-level options: `connection`, `listen`, `request`, `response`,
172
- `static`, `cors`, `securityHeaders`, `rateLimit`, `cookie`, `csrf`,
173
- `compress`.
189
+ Common top-level options:
190
+
191
+ | Option | Purpose |
192
+ |-------------------|-----------------------------------------------|
193
+ | `connection` | Transport-specific Node.js server options. |
194
+ | `listen` | Host, port, and backlog for binding. |
195
+ | `request` | Request parsing and proxy trust. |
196
+ | `response` | Response shaping (ETag, charset). |
197
+ | `static` | Static file serving. |
198
+ | `cors` | Cross-Origin Resource Sharing. |
199
+ | `securityHeaders` | HTTP security response headers. |
200
+ | `rateLimit` | Request rate limiting. |
201
+ | `cookie` | Cookie parsing and cookie-backed sessions. |
202
+ | `csrf` | CSRF protection. |
203
+ | `compress` | Response compression. |
174
204
 
175
- These options enable server features. When enabled, the corresponding
176
- behavior is applied before user-registered middleware.
205
+ These options enable server features. When enabled, the corresponding behavior is applied before user-registered middleware.
177
206
 
178
- See the [full API reference](./Docs/BOO_SERVER_API.md) for the complete
179
- option shapes and defaults.
207
+ See the [full API reference](https://github.com/vgbr-dev/boo-labs/wiki) for the complete option shapes and defaults.
180
208
 
181
209
  ## Lifecycle and Events
182
210
 
@@ -186,45 +214,75 @@ await server.listen();
186
214
  await server.close();
187
215
  ```
188
216
 
189
- States: `idle` → `starting` → `listening` → `stopping` → `closed` (or `error`).
217
+ States:
218
+
219
+ | State | Description |
220
+ |-------------|------------------------------------------------------|
221
+ | `idle` | Initial state. The server has not started. |
222
+ | `starting` | The server is starting up. |
223
+ | `listening` | The server is accepting connections. |
224
+ | `stopping` | The server is shutting down. |
225
+ | `closed` | The server has closed. |
226
+ | `error` | The server encountered an error and cannot continue. |
227
+
228
+ Events:
190
229
 
191
- Events: `listen`, `close`, `error`, `exchange:start`, `exchange:end`,
192
- `exchange:error`. Convenience methods: `onListen()`, `onClose()`,
193
- `onError()`, `onExchangeStart()`, `onExchangeEnd()`, `onExchangeError()`.
230
+ | Event | Convenience method | Description |
231
+ |------------------|-----------------------|----------------------------------|
232
+ | `listen` | `onListen()` | The server started listening. |
233
+ | `close` | `onClose()` | The server has closed. |
234
+ | `error` | `onError()` | A server error occurred. |
235
+ | `exchange:start` | `onExchangeStart()` | An exchange began processing. |
236
+ | `exchange:end` | `onExchangeEnd()` | An exchange ended. |
237
+ | `exchange:error` | `onExchangeError()` | An exchange failed. |
194
238
 
195
- `Server` implements `Symbol.asyncDispose` for `await using` when the
196
- runtime supports it.
239
+ `Server` implements `Symbol.asyncDispose` for `await using` when the runtime supports it.
197
240
 
198
241
  ## IPC
199
242
 
200
- An IPC API over WebSocket at `/ipc`. Supports request-response channels
201
- (`handle` / invoke) and one-way events (`on` / event). Available while the
243
+ An IPC API over WebSocket at `/ipc`. Supports request-response channels (`handle` / invoke) and one-way events (`on` / event). Available while the
202
244
  server is listening via `server.ipc`.
203
245
 
204
- See the [full API reference](./Docs/BOO_SERVER_API.md) for the wire protocol
205
- and handler details.
246
+ ```js
247
+ await server.listen();
248
+
249
+ server.ipc.handle('users:get', async (id) => {
250
+ return usersRepository.findById(id);
251
+ });
252
+
253
+ server.ipc.on('analytics:event', (event) => {
254
+ analytics.record(event);
255
+ });
256
+ ```
257
+
258
+ See the [full API reference](https://github.com/vgbr-dev/boo-labs/wiki) for the wire protocol and handler details.
206
259
 
207
260
  ## Errors
208
261
 
209
262
  Public APIs throw errors that extend `Error` and expose a stable `code`
210
- property. Error types include `ServerConfigurationError`, `RequestError`,
211
- `ResponseError`, `RouterError`, `PathnamePatternError`, `MiddlewareError`,
212
- `ServerError`, and `IPCError`.
263
+ property.
264
+
265
+ | Error | Domain |
266
+ |----------------------------|----------------------------------------------|
267
+ | `ServerConfigurationError` | Server configuration validation. |
268
+ | `RequestError` | Incoming request processing. |
269
+ | `ResponseError` | Outgoing response construction. |
270
+ | `RouterError` | Router route registration. |
271
+ | `PathnamePatternError` | Pathname pattern validation. |
272
+ | `MiddlewareError` | Middleware validation. |
273
+ | `ServerError` | Server lifecycle and state transitions. |
274
+ | `IPCError` | IPC operations. |
213
275
 
214
- Error codes are documented in the
215
- [project wiki](https://github.com/vgbr-dev/boo-labs/wiki/Errors).
276
+ Error codes are documented in the [project wiki](https://github.com/vgbr-dev/boo-labs/wiki/Errors).
216
277
 
217
278
  ## Documentation
218
279
 
219
- - [Full API reference](./Docs/SERVER_API.md) — complete public API,
220
- configuration options, response methods, IPC protocol, and more.
280
+ - [Full API reference](https://github.com/vgbr-dev/boo-labs/wiki) — complete public API, configuration options, response methods, IPC protocol, and more.
221
281
 
222
282
  ## License
223
283
 
224
- Distributed under the MIT License. See the [LICENSE](./LICENSE) file for
225
- details.
284
+ Distributed under the MIT License. See the [LICENSE](./LICENSE) file for details.
226
285
 
227
286
  ## Dedication
228
287
 
229
- This project is named after my sister — "Boo". Her nickname gave this
230
- project its name.
288
+ This project is named after my sister — "Boo". Her nickname gave this project its name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boo-labs/server",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A zero-dependency, frameworkless HTTP server for Node.js, built around Clean Architecture principles.",
5
5
  "keywords": [
6
6
  "http-server",