{"library":"objective-http","title":"Objective HTTP Server","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install objective-http"],"cli":null},"imports":["const { Server } = require('objective-http').server;","const { server: autoconfigServer } = require('objective-http').server.autoconfig;","const { handler, request, response } = require('objective-http').server;\nconst { EndpointHandler } = handler.endpoint;\nconst { JsonServerRequest } = request.chunk;\nconst { LogErrorHandler } = handler.error;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const { server: autoconfigServer } = require('objective-http').server.autoconfig;\nconst { env } = require('node:process');\n\nclass MyEndpoint {\n    route = {\n        method: 'GET',\n        path: '/hello'\n    }\n\n    async handle(request) {\n        console.log(`Received request for: ${request.url}`);\n        try {\n            // Simulate some async processing\n            await new Promise(resolve => setTimeout(resolve, 50));\n            return {\n                status: 200,\n                body: 'Hello, Objective HTTP!'\n            };\n        \n        } catch (e) {\n            console.error('Error handling request:', e);\n            return {\n                status: 500,\n                body: 'Internal server error'\n            };\n        }\n    }\n}\n\n// Start the server using autoconfig\nautoconfigServer({\n    env: env,\n    endpoints: [\n        new MyEndpoint()\n    ],\n    options: { port: 3000 } // You can pass http.createServer options here\n})\n.then(() => console.log('Objective HTTP server listening on port 3000'))\n.catch(err => console.error('Failed to start server:', err));\n\n// Optional: Keep the process alive or graceful shutdown\n// process.on('SIGINT', () => { console.log('Shutting down...'); process.exit(0); });\n","lang":"javascript","description":"This quickstart demonstrates setting up a basic HTTP server using `objective-http`'s `autoconfig` utility, defining a simple GET endpoint, and starting the server.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}