In this lesson, you counted the lines of the plot board you’ve built and sorted them: the lines that decide what the board says, and the lines any server needs to route a request and read its body.
Key Points
- The board answers all three of Mrs. Okafor’s calls.
GET /plots?vacant=truelists the free plots,GET /plots/7gives one plot’s size, andPOST /waitlistadds an entry to the waiting list. - As this course wrote it, the board is five files and 250 lines, not counting blank ones.
server.tshas 128,body.ts55,responses.ts23,plots.ts17 andwaitlist.ts27. Your own board may differ by a few lines. - Routing and parameters take 57 lines, all in
server.ts. They’re theHandlerandRoutetypes, theroutestable,routePath(), and the listener from parsing the URL to calling the handler, with its404and its405withAllow. Two more lines inside the handlers readvacantfrom the query string and split the plot number out of the path. Most of this is dispatch machinery, but the route list and the404and405answers are choices you made. - Reading bodies takes 60 lines. All 55 lines of
body.tsare there to read one, with every check you built: the415for the wrong type, the413for a body that’s too large, a client that hangs up, an empty body and broken JSON. Five more lines injoinWaitlist()callreadJson()and send its error. - Together, that’s 117 of your 250 lines, nearly half. Most of the other 133 are what the board knows and decides: the plots, the entry check in
toEntry(), the waiting list file inaddToWaitlist(), the error shape insendError(), and the status each answer gets, like the404for a missing plot. - Line counts are a rough measure. This board is small, so treat the split as a picture of where your work went, not as a rule about servers in general.
- Every server needs routing and body reading, and it barely changes between servers. That’s what a framework is for. The next course on the path rebuilds this board with Express, which matches the method and the path and reads JSON bodies for you. You still choose the routes, the limits, such as the size limit, and what each answer says, such as the
415and the error shape. That’s all you need about frameworks for now.
Because you wrote these lines by hand, you’ll know what a framework is doing for you. Next, in Project: The Hollybank Plot Board, you’ll build Mrs. Okafor’s board from her brief, starting fresh and bringing your helpers along.