High-Speed Routing
Kitwork uses a high-performance Radix Tree router. Build sub-millisecond APIs with ease.
Basic Routing
Define routes using the router object. Supported methods include GET, POST, PUT, DELETE, and PATCH.
router.get("/").handle((req, res) => {
return res.text("Hello Kitwork!");
});
Route Parameters
Extract parameters from the URL using the :name syntax.
const id = req.params("id");
return res.json({ userId: id });
});
Route Groups
Prefix related endpoints dynamically using the router.group() API for clean middleware scoping.
// This endpoint serves /api/v1/health
api.get("/v1/health").handle((req, res) => {
return res.json({ status: "healthy" });
});
Request & Response API
Manipulate queries, headers, and request states, then render custom response body types.
const token = req.headers("Authorization");
const queryVal = req.query("search").text();
return res
.status(200)
.json({
token: token,
search: queryVal
});
});
Body Parsing & POST
Extract JSON request payloads or URL-encoded form inputs safely inside write endpoints.
const body = req.body().json();
const newUser = db.table("user").create({
username: body.username,
email: body.email
});
return res.status(201).json(newUser);
});
Custom Headers & Status Codes
Fine-tune responses by overriding default headers and setting custom response statuses.
return res
.status(202)
.header("X-Custom-Header", "Kitwork-Sovereign")
.json({ accepted: true });
});
