A utility class for constructing URLs with typed query parameters.
This class allows you to dynamically build a URL with typed query parameters. Supports method chaining for setting multiple parameters before building the final URL.
interface Params { userId: number; search: string; isActive: boolean;}const url = new UrlBuilder<Params>("https://example.com") .setParam("userId", 123) .setParam("search", "test") .setParam("isActive", true) .build();console.log(url); // "https://example.com?userId=123&search=test&isActive=true" Copy
interface Params { userId: number; search: string; isActive: boolean;}const url = new UrlBuilder<Params>("https://example.com") .setParam("userId", 123) .setParam("search", "test") .setParam("isActive", true) .build();console.log(url); // "https://example.com?userId=123&search=test&isActive=true"
A generic type extending Record<string, any>, representing the expected query parameters.
Record<string, any>
Creates an instance of UrlBuilder.
UrlBuilder
The base URL to which query parameters will be appended.
Builds and returns the final URL with the appended query parameters.
The fully constructed URL with query parameters.
Sets a query parameter in the URL.
Supports method chaining to allow setting multiple parameters fluently.
A key of T, representing a valid query parameter name.
T
The key of the query parameter.
The value of the query parameter.
Returns the current UrlBuilder instance for method chaining.
A utility class for constructing URLs with typed query parameters.
This class allows you to dynamically build a URL with typed query parameters. Supports method chaining for setting multiple parameters before building the final URL.
Example Usage