http-url-builder is a lightweight utility designed to simplify the construction of HTTP URLs, primarily for REST API interactions. It provides a fluent API to append path segments, add query parameters, and integrate path variables, streamlining the process of creating complex endpoints. The current stable version is 1.1.0, which notably introduced support for path variables. As a relatively new but actively maintained package, its release cadence is feature-driven, with updates focused on enhancing usability and functionality. Key differentiators include its explicit support for path variables, a clear and chainable API, and native TypeScript typings, which ensure a robust development experience compared to manual string concatenation or less specialized URL manipulation libraries.
npm install http-url-builderVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate `URLBuilder`, add path segments, specify path variables, append query parameters, and finally build the complete URL string for various API endpoints, including proper URL encoding.
Upgrade to v1.1.0 or newer and refactor path-building logic to use the `addPath('/{variableName}')` followed by `withPathVariables({ variableName: 'value' })` pattern.Provide clean, unencoded strings for path segments and query parameter values. For path variables, verify exact case-sensitive matching between the placeholder in `addPath` and the key in `withPathVariables`.
Consult your API documentation. If multiple parameters for the same key should be treated as a single, combined value, construct that combined string (e.g., `value1,value2`) before calling `addQuery`. Otherwise, chaining `addQuery('key', 'value1').addQuery('key', 'value2')` will produce separate parameters.Ensure you are using `import { URLBuilder } from 'http-url-builder';` if the library exports it as a named export. If using CommonJS, check the library's documentation for the correct `require` syntax, which might involve `const { URLBuilder } = require('http-url-builder');` or `const URLBuilder = require('http-url-builder').URLBuilder;`.Ensure that every path variable placeholder defined within `addPath` (e.g., `{userId}`) has an exact matching key in the object passed to `withPathVariables({ userId: 'actualValue' })` before calling `build()`.No dependency data recorded yet.