HTTP Server
Request & Response
Enhanced methods for handling HTTP interactions, redirections, and server-side forwarding.
res.html(htmlString)
A convenience method for sending HTML responses. It automatically sets the Content-Type to text/html; charset=utf-8.
typescript
app.get("/welcome", (req, res) => {
res.html("<h1>Welcome to XyPriss</h1>");
});Redirections
XyPriss supports both route-level and request-level redirections for maximum flexibility.
Route-Level (app.redirect)
typescript
// Permanent redirect (301)
app.redirect("/old-path", "/new-path");
// Temporary redirect (302)
app.redirect("/promo", "https://external.com", 302);Request-Level (req.redirect)
typescript
app.get("/secure", (req, res) => {
if (!req.session.user) return req.redirect("/login");
// ... logic
});Server-Side Forwarding
Asynchronously forwards the current request to another endpoint (internal or external). It inherits the same method, body, and headers by default.
typescript
app.post("/submit", async (req, res) => {
// Delegate validation to an internal service
const validation = await req.forward("/internal/validate");
if (!validation.valid) return res.status(400).json(validation);
res.success({ message: "Data accepted" });
});- Internal Resolution: Automatically resolves relative paths to the current server's port.
- Auto-Parsing: Automatically parses JSON responses from the forwarded target.
XJSON API
Learn about the advanced JSON serialization engine for complex data.
