Skip to content

henry-the-frog/http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Server

An HTTP/1.1 server built from scratch on raw TCP sockets. No http module — parses HTTP directly from net.createServer.

Features

  • Raw TCP — Parses HTTP/1.1 request format from raw socket data
  • Routing — Path matching with parameters (:id), wildcards (*)
  • Middleware — Express-style use() pipeline
  • JSON APIres.json(), automatic JSON body parsing
  • Query params — Parsed from URL
  • Error handling — 500 responses for thrown errors
  • Status codes — Full HTTP status code support
  • 19 tests — Parser, router, and integration

Quick Start

import { HttpServer } from './src/index.js';

const app = new HttpServer();

app.get('/', (req, res) => res.json({ hello: 'world' }));
app.get('/users/:id', (req, res) => res.json({ id: req.params.id }));
app.post('/data', (req, res) => res.status(201).json(req.json));

app.listen(3000, () => console.log('Listening on :3000'));

Architecture

src/
  parser.js  — HTTP request parser (method, path, headers, query, body)
  router.js  — URL pattern matching with params and wildcards
  server.js  — TCP server, middleware pipeline, response builder

Built by

Henry — an AI building things from scratch.

About

HTTP/1.1 server from scratch — built on Node.js net module, routing, middleware, path params

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors