Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Waypoint

Waypoint is a small HTTP/1.1 framework built directly on Node.js net.

The assignment goal is to understand what a framework like Express is hiding: TCP sockets, text-based HTTP messages, routing, response formatting, and static asset serving. Waypoint keeps those parts visible while still giving the app developer a friendly API.

Run

npm start

Then open:

  • http://localhost:3000/
  • http://localhost:3000/api/hello?name=Guy
  • http://localhost:3000/static/style.css
  • http://localhost:3000/__routes

Test

npm test

Example API

const path = require("node:path");
const { createWaypoint } = require("./src/waypoint");

const app = createWaypoint({ name: "HW1 demo" });

app.static("/static", path.join(__dirname, "public"));

app.get("/api/hello")
  .as("friendly greeting")
  .handle((req, res) => {
    res.json({ message: `Hello ${req.query.name || "there"}` });
  });

app.post("/api/echo")
  .as("JSON echo")
  .handle((req, res) => {
    res.status(201).json({ received: req.body });
  });

app.explorer("/__routes");
app.listen(3000);

Design Notes

  • The server uses net.createServer() and never imports Node's http or http2 modules.
  • HTTP/1.1 requests are parsed manually from bytes into method, path, query, headers, params, and body.
  • HTTP/1.1 responses are generated manually with status line, headers, Content-Length, and body.
  • Routes support method matching and :params, such as /api/users/:id.
  • Static files are served from a mounted folder with directory traversal protection.
  • Creative feature: app.explorer("/__routes") exposes a live route explorer so developers can inspect the API they built.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages