A typical web server looks like a function of type
(request: Request) => Promise<Response>for some types Request and Response.
This is a minimal tool for defining and combining such functions.
See readme.test.ts for an example application.
The Request type can be any record, but this library assumes a few special attributes:
-
method:string- The HTTP request method. -
path:string | null- A relative URL pathname constructed from the request path, (e.g. asnew URL(request.url).pathname.slice(1)to remove the leading slash but perhaps modified by intermediate processing before reaching the server). -
parent:string- When descending into adynamicDirectory, the segment that was popped off the front of the URL path.
The Response type can be anything.