Registry / http-networking / objective-http

objective-http

JSON →
library2.1.6jsnpmunverified

objective-http is a Node.js library that provides Object-Oriented Programming (OOP) proxy classes for constructing HTTP servers. It wraps Node.js's native `http` module, abstracting away low-level stream interactions into a more structured, class-based API. The library emphasizes a clear separation of concerns, allowing developers to define server logic through `Endpoint` classes (for route and request handling) and `Handler` classes (for error handling and request/response stream processing). Currently stable at version 2.1.6, the package appears to have a fairly active release cadence with frequent patch updates. It differentiates itself by offering a highly modular and extensible architecture for building HTTP services, including an `autoconfig` feature for simpler server setups, contrasting with more opinionated frameworks or purely functional approaches.

npm install objective-http
INSTALL
IMPORT
SIG · OBJECTIVE-HTTP
O
objective-http
http-networkingjavascriptv2.1.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Server
const { Server } = require('objective-http').server;
import { Server } from 'objective-http';
The primary `Server` class is exposed via the `.server` namespace in CommonJS. Direct ESM imports like `import { Server } from 'objective-http';` are likely incorrect or unsupported due to the deep nesting of exports.
autoconfig
const { server: autoconfigServer } = require('objective-http').server.autoconfig;
import { autoconfigServer } from 'objective-http/server/autoconfig';
The autoconfiguration utility is nested under `server.autoconfig`. It's exported as `server` within that module, so it's common to rename it on import.
EndpointHandler, JsonServerRequest, LogErrorHandler
const { handler, request, response } = require('objective-http').server; const { EndpointHandler } = handler.endpoint; const { JsonServerRequest } = request.chunk; const { LogErrorHandler } = handler.error;
Many core classes are deeply nested within the `handler`, `request`, and `response` namespaces. Proper CommonJS destructuring is required to access them.

This quickstart demonstrates setting up a basic HTTP server using `objective-http`'s `autoconfig` utility, defining a simple GET endpoint, and starting the server.

const { server: autoconfigServer } = require('objective-http').server.autoconfig; const { env } = require('node:process'); class MyEndpoint { route = { method: 'GET', path: '/hello' } async handle(request) { console.log(`Received request for: ${request.url}`); try { // Simulate some async processing await new Promise(resolve => setTimeout(resolve, 50)); return { status: 200, body: 'Hello, Objective HTTP!' }; } catch (e) { console.error('Error handling request:', e); return { status: 500, body: 'Internal server error' }; } } } // Start the server using autoconfig autoconfigServer({ env: env, endpoints: [ new MyEndpoint() ], options: { port: 3000 } // You can pass http.createServer options here }) .then(() => console.log('Objective HTTP server listening on port 3000')) .catch(err => console.error('Failed to start server:', err)); // Optional: Keep the process alive or graceful shutdown // process.on('SIGINT', () => { console.log('Shutting down...'); process.exit(0); });
Debug
Known issues
breakingVersion 1.3.0 introduced a 'new import signature'. This likely changed how classes and functions were exported, requiring users to update their `require` statements or destructuring paths. Code written for versions prior to 1.3.0 will likely break due to module resolution errors.
fix
Review the README and source code for the correct import paths and destructuring patterns. Update `require()` calls to match the new module structure.
affects: >=1.3.0 <1.4.0
breakingVersion 1.4.0 explicitly 'removed json request and response' functionality. If your application relied on `JsonServerRequest` or `JsonServerResponse` classes in versions before 1.4.0, your code would have broken. Note that these classes were later reintroduced in version 2.x, but with potential API changes.
fix
For versions 1.x, you would need to implement custom JSON parsing/serialization. For versions 2.x and above, `JsonServerRequest` and `JsonServerResponse` have been re-added, but verify their usage patterns as they might differ from pre-1.4.0 versions.
affects: >=1.4.0 <2.0.0
gotchaThe library heavily relies on deeply nested object structures for its classes and utilities, especially when not using `autoconfig`. For example, `EndpointHandler` is under `objective-http.server.handler.endpoint.EndpointHandler`. This can lead to verbose `require` statements and makes direct ESM imports challenging or impossible.
fix
Prefer the `autoconfig` utility for simpler server setups. When building custom server configurations, carefully follow the provided examples for destructuring the `objective-http.server` object to access nested components.
affects: >=1.0.0
gotchaThe `autoconfig` utility requires an array of `Endpoint` instances and an `env` object. Forgetting to provide these, or providing them in an incorrect format, can lead to server startup failures or requests not being handled correctly.
fix
Always ensure the `endpoints` array contains valid instances of classes implementing the `Endpoint` interface (with `route` and `handle` methods). Pass `process.env` or a compatible object as the `env` parameter.
affects: >=2.1.2
Errors
Common errors & fixes
TypeError: (0 , server_1.Server) is not a constructor
Attempting to import `Server` using an incorrect ESM syntax or path when the package primarily uses CommonJS `require` with nested exports.
fix
Use the correct CommonJS `require` statement: `const { Server } = require('objective-http').server;`
Error: Cannot find module 'objective-http/server'
This error typically occurs when attempting to use a direct path import for a submodule (`objective-http/server`) in a CommonJS context, or if the package's internal structure doesn't expose modules in that specific way for direct import.
fix
The primary entry point for server components is usually `require('objective-http').server`. Avoid direct path imports like `require('objective-http/server')` unless explicitly documented.
ReferenceError: MyEndpoint is not defined
When using `autoconfig` or manually configuring the `Server`, an `Endpoint` class (like `MyEndpoint`) is referenced but not defined or correctly imported within the scope.
fix
Ensure that any custom `Endpoint` classes are properly defined and instantiated before being passed to the server configuration. For example, `class MyEndpoint { ... }`.
Upgrade
Version history
2.1.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
objective-http — npm install objective-http · libregistry