Registry / devops / rest-url-builder

rest-url-builder

JSON →
library1.0.6jsnpmunverified

A lightweight TypeScript library for building REST URLs with easy parameter substitution, query string handling, and base URL support. Version 1.0.6 is the latest stable release with no breaking changes in the v1.x series. Differentiates from other URL builders by focusing specifically on RESTful patterns with typed parameter placeholders and automatic encoding. Suitable for both browser and Node.js environments.

npm install rest-url-builder
INSTALL
IMPORT
SIG · REST-URL-BUILDER
R
rest-url-builder
devopsjavascriptv1.0.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

UrlBuilder
import { UrlBuilder } from 'rest-url-builder'
import UrlBuilder from 'rest-url-builder'
UrlBuilder is a named export, not default. TypeScript types are included.
RestUrlBuilder
import { RestUrlBuilder } from 'rest-url-builder'
const RestUrlBuilder = require('rest-url-builder')
ESM-only; CommonJS require does not work.
UrlBuilderOptions
import type { UrlBuilderOptions } from 'rest-url-builder'
import { UrlBuilderOptions } from 'rest-url-builder'
Use 'import type' for TypeScript type imports to avoid runtime issues.

Creates a REST URL with path parameters and query string using the UrlBuilder class.

import { UrlBuilder } from 'rest-url-builder'; const builder = new UrlBuilder('https://api.example.com', { encode: true }); // Define a URL template with placeholders const url = builder .path('/users/:userId/posts/:postId') .query({ limit: 10, offset: 0 }) .build({ userId: '123', postId: 'abc' }); console.log(url); // Output: https://api.example.com/users/123/posts/abc?limit=10&offset=0
Debug
Known issues
gotchaParameters in the path template are case-sensitive and must match exactly the keys provided in build().
fix
Ensure placeholder names in .path() match exactly the keys passed to .build(). For example, path('/users/:userId') requires build({ userId: '...' }) not { userid: '...' }.
affects: >=1.0.0
gotchaThe 'encode' option in the constructor does not encode query parameters automatically; only path segments are encoded.
fix
If you need query parameter encoding, manually encode values before passing to .query() or use a third-party library.
affects: >=1.0.0
gotchaThe .build() method expects all path parameters to be provided; missing parameters will throw an error.
fix
Always provide all parameters defined in the path template to .build(). Optional parameters are not supported.
affects: >=1.0.0
breakingIn version 1.0.0, the constructor signature changed from new UrlBuilder(options) to new UrlBuilder(baseUrl, options).
fix
Update to new UrlBuilder(baseUrl, options) if upgrading from pre-1.0.0 versions.
affects: >=1.0.0
deprecatedThe 'setBaseUrl' method is deprecated in v1.0.0+. Use the constructor parameter instead.
fix
Pass base URL via constructor: new UrlBuilder('https://example.com', options).
affects: >=1.0.0
Errors
Common errors & fixes
UrlBuilder is not a constructor
Using CommonJS require() with named export incorrectly.
fix
Use ESM import: import { UrlBuilder } from 'rest-url-builder'
Cannot find module 'rest-url-builder'
Package not installed or incorrect version.
fix
Install the package: npm install rest-url-builder
TypeError: Missing parameter 'userId'
Required path parameter not provided in build() call.
fix
Provide all parameters defined in the path template to .build().
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
rest-url-builder — npm install rest-url-builder · libregistry