Parameters & Constraints

XyPriss XyPriss Router supports dynamic path segments with optional inline Regex constraints and type-safe shortcuts, all enforced at the routing layer.

Path Parameters

Parameters are defined using the :name prefix and are accessible via req.params.

typescript
router.get("/users/:id", (req, res) => {
    const userId = req.params.id;
    res.json({ userId });
});

// Multiple parameters
router.get("/posts/:year/:month/:slug", (req, res) => {
    const { year, month, slug } = req.params;
    res.json({ year, month, slug });
});

Regex Constraints

You can enforce a specific format on a parameter directly in the path definition using standard Regular Expressions.

typescript
// Only matches when 'id' consists of digits
router.get("/users/:id(\\d+)", (req, res) => {
    res.json({ userId: req.params.id });
});

// Matches slugs like: word-word-word
router.get("/shop/:slug([a-z]+-[a-z]+-[a-z]+)", (req, res) => {
    res.json({ slug: req.params.slug });
});

Typed Parameters

For cleaner definitions, use built-in type shortcuts. XyPriss handles the regex generation and validation for you.

typescript
// Only matches numbers
router.get("/items/:id<number>", (req, res) => {
    res.json({ id: req.params.id });
});

// Only matches UUIDs
router.get("/jobs/:uuid<uuid>", (req, res) => {
    res.json({ uuid: req.params.uuid });
});

// Enum constraint
router.get("/status/:type<enum(active,inactive,pending)>", (req, res) => {
    res.json({ type: req.params.type });
});
Type NameDescription / UsageExample Match
numberAny valid floating-point number.123, 45.67
integerWhole numbers only.42, -7
booleanMatches "true" or "false".true
uuidStandard UUID v4 format.550e8400-e29b...
alphaAlphabetic characters (A-Z) only.profile
alphanumericLetters and numbers.user123
string(min,max)Length constraints (inclusive).slug<string(3,20)>
number(min,max)Value range constraints.age<number(18,99)>
enum(a,b,c)Explicit allowed values.v1, v2, v3
Layer-1 Validation

Requests that don't satisfy constraints are rejected at the routing layer, never reaching your application logic.

Multi-Segment Support

Combine multiple parameters in a single segment, e.g.,/files/:name.:ext.

Wildcard Routes

XyPriss distinguishes between single-segment and recursive wildcards.

  • Single Wildcard (*): Matches exactly one segment within a path. Accessible via req.params["*"].
  • Double Wildcard (**): Matches multiple segments recursively. Accessible via req.params["**"].
typescript
router.get("/files/*", (req, res) => {
    const filename = req.params["*"];
    res.json({ filename });
});

router.get("/api/**", (req, res) => {
    const capturedPath = req.params["**"];
    res.json({ capturedPath });
});

Query Parameters

Query strings are automatically parsed and made available viareq.query.

typescript
// GET /search?q=xypriss&limit=10
router.get("/search", (req, res) => {
    const { q, limit } = req.query;
    res.json({ query: q, limit: Number(limit) });
});
Security Guards

Implement declarative route protection using the XyGuard API.