Skip to Content
Drash v3 is in beta. APIs may change.

Polyfill

The chain matches request URLs with a URLPattern-like class. Which one it uses is the only difference between the native and polyfill entry points.

import { URLPatternPolyfill } from "@drashland/drash/standard/polyfill/URLPatternPolyfill.js"; const app = Application .builder() .urlPatternClass(URLPatternPolyfill) .resources(Home) .build();

The Contract

Whatever class you supply must be constructible with { pathname } and expose exec():

new URLPatternClass({ pathname: string }); exec(url: string): { pathname: { groups: Record<string, string> } } | null;

exec() returns null for no match. On a match, the path params live in pathname.groups.

URLPatternPolyfill

The implementation handed to the chain by modules/http.polyfill.js, for runtimes without a global URLPattern — Node and Bun.

MemberTypeNotes
pathnamestringThe pattern this instance was built with
exec(url)methodReturns the match result, or null

CustomUrlPattern

The pattern-compiling class URLPatternPolyfill is built on. It exports an ExecResult type describing the shape above.

You would reach for this directly only when building a matcher of your own rather than a chain.

Which One You Get

Entry pointURLPattern used
modules/http.native.jsThe runtime’s global
modules/http.polyfill.jsURLPatternPolyfill

Both entry points call .urlPatternClass() for you. Calling it yourself overrides whatever the entry point injected — see Native vs. Polyfill.

.urlPatternClass() is required. A chain built without one throws at build():

`this.urlPatternClass(Resource)` not called. Cannot create RequestChain without a `URLPattern`-like class.

That is why the entry points exist at all — each calls it for you.

Last updated on