
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
http-url-builder
Advanced tools
branch | build | coverage |
---|---|---|
main | ||
develop |
Utility to help building http urls for your API.
Using npm:
npm install http-url-builder
Using bower:
bower install http-url-builder
Using yarn:
yarn add http-url-builder
To install the latest version with security updates applied use @dev
tag when installing:
npm install http-url-builder@dev
Using bower:
bower install http-url-builder@dev
Using yarn:
yarn add http-url-builder@dev
Basic setup:
import { UrlBuilder } from 'http-url-builder';
const url = UrlBuilder.create('localhost', 8080).build();
console.log(url);
// https://localhost:8080
Build an url:
// 'false' uses 'http' instead of 'https'
const url = UrlBuilder.create('localhost', 8080/*, false*/)
.addPath('foo')
.addPathVariable('John Doe')
.addPath('bar')
.addQueryParam('baz', 'qux')
.addQueryParam('test', 123)
.build();
console.log(url);
// https://localhost:8080/foo/John Doe/bar?baz=qux&test=123
addPath()
does not allow spaces in the url and automatically trims the path value to prevent errors.
addPathVariable()
instead allows to insert spaces since query params do not need to follow the strict rules applied to paths. Moreover, /
characters will be replaced with %2F
.
const url = UrlBuilder.create('localhost', 8080)
.addPath('example')
// 'true' will trim the path variable as it happens with .addPath()
.addPathVariable(' John/Doe '/*, true*/)
.addPath('operation')
.build();
console.log(url);
// https://localhost:8080/example/ John%2FDoe /operation
addQueryParam()
accepts strings, numbers, booleans and objects. Objects will be converted to their JSON representation to create the url.
const obj = {
foo: 'bar',
baz: 0,
qux: true,
};
const url = UrlBuilder.create('localhost', 8080)
.addPath('example')
.addQueryParam('myObj', obj)
.build();
console.log(url);
// https://localhost:8080/example?myObj={"foo":"bar","baz":0,"qux":true}
Each addPath()
, addPathVariable()
and addQueryParam()
operation creates a new UrlBuilder instance.
Thanks to immutability, paths can not be accidentally modified:
const base = UrlBuilder.create('localhost', 8080).addPath('base');
const fooUrl = base.addPath('foo');
const barUrl = base.addPath('bar');
console.log(base.build()); // https://localhost:8080/base
console.log(fooUrl.build()); // https://localhost:8080/base/foo
console.log(barUrl.build()); // https://localhost:8080/base/bar
If you already have an url, you can convert it to an UrlBuilder instance by using its constructor:
const url = new UrlBuilder("https://localhost:8080/my/path");
FAQs
Utility to help building http urls
The npm package http-url-builder receives a total of 510 weekly downloads. As such, http-url-builder popularity was classified as not popular.
We found that http-url-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.