Routing
Every Zipper applet has a built-in router that maps a path to a corresponding handler function.
Index route (root path)
Every Zipper applet must have a main.ts
file that exports a handler
function. This function will be called when the applet is invoked at the root URL, without a path.
Adding new paths
Adding a new path to a Zipper applet is simple. All you need to do is create a new file in your applet which exports a function called handler
. The path will be named after the file name. For example, if you create a file called set.ts
which exports a function called handler
, then your applet will have a /set
path.
If a file does not export a handler function, it will not be added to the router. This is useful for creating library files that can be imported into other files.
Note that Zipper already uses the /run
, /api
, and /raw
paths (see Basic Concepts). Avoid naming files in your project with these names, as they will be ignored.
Route methods
Every route can accept GET
and POST
HTTP request methods. See Basic Concepts for request and response specifications.
If you'd like to modify the behavior of your handler function based on the HTTP method, you can inspect the request object that is part of the context object passed to the handler.