0.0.3 • Published 11 months ago
h3p-server v0.0.3
Simple HTTP Server
A lightweight HTTP server implementation in TypeScript.
Installation
npm install h3p-server
Usage
import { createServer, Router } from 'simple-http-server';
const router = new Router();
router.addRoute('GET', '/', (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World!');
});
const server = createServer(router);
server.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
API
createServer(router: Router, port: number): net.Server
Creates and starts an HTTP server with the given router on the specified port.
Router
A class for managing routes.
addRoute(method: string, path: string, handler: RouteHandler): void
findRoute(method: string, path: string): RouteHandler | null
RouteHandler
A function type for handling routes: (req: ParsedRequest, res: ResponseWriter) => void
ParsedRequest
An interface representing a parsed HTTP request.
ResponseWriter
An interface for writing HTTP responses.
License
MIT