{"id":36502328,"url":"https://github.com/gturi/url-builder","last_synced_at":"2026-01-12T02:24:21.800Z","repository":{"id":37055656,"uuid":"312787526","full_name":"gturi/url-builder","owner":"gturi","description":"Utility to help building http urls for your API.","archived":false,"fork":false,"pushed_at":"2023-03-06T23:59:32.000Z","size":922,"stargazers_count":0,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-05T08:54:28.260Z","etag":null,"topics":["rest-api","typescript","url"],"latest_commit_sha":null,"homepage":"https://github.com/gturi/url-builder/blob/gh-pages/README.md","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gturi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-14T09:45:51.000Z","updated_at":"2023-05-07T12:01:29.000Z","dependencies_parsed_at":"2023-02-16T23:45:42.864Z","dependency_job_id":null,"html_url":"https://github.com/gturi/url-builder","commit_stats":null,"previous_names":["FlamingTuri/url-builder","flamingturi/url-builder"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/gturi/url-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gturi%2Furl-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gturi%2Furl-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gturi%2Furl-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gturi%2Furl-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gturi","download_url":"https://codeload.github.com/gturi/url-builder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gturi%2Furl-builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28332282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rest-api","typescript","url"],"created_at":"2026-01-12T02:24:21.169Z","updated_at":"2026-01-12T02:24:21.795Z","avatar_url":"https://github.com/gturi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UrlBuilder\n\n| branch | build | coverage |\n| --- | --- | --- |\n| main | [![lint-and-test](https://github.com/FlamingTuri/url-builder/actions/workflows/lint-and-test.yml/badge.svg)](https://github.com/FlamingTuri/url-builder/actions/workflows/lint-and-test.yml) | [![Coverage Status](https://coveralls.io/repos/github/FlamingTuri/url-builder/badge.svg?branch=main)](https://coveralls.io/github/FlamingTuri/url-builder?branch=main) |\n| develop | [![lint-and-test](https://github.com/FlamingTuri/url-builder/actions/workflows/lint-and-test.yml/badge.svg?branch=develop)](https://github.com/FlamingTuri/url-builder/actions/workflows/lint-and-test.yml) | [![Coverage Status](https://coveralls.io/repos/github/FlamingTuri/url-builder/badge.svg?branch=develop)](https://coveralls.io/github/FlamingTuri/url-builder?branch=develop) |\n\nUtility to help building http urls for your API.\n\n## Installing\n\n```bash\nnpm install http-url-builder\n```\n\nTo install the latest version with security updates applied use `@dev` tag when installing:\n\n```bash\nnpm install http-url-builder@dev\n```\n\n## Examples\n\nImporting the library:\n\n```js\n// old CommonJS syntax\nconst UrlBuilder = require('http-url-builder').UrlBuilder;\n// new ES6 syntax\nimport { UrlBuilder } from 'http-url-builder';\n```\n\nBasic setup:\n\n```js\nconst url = UrlBuilder.create('localhost', 8080).build();\n\nconsole.log(url);\n// https://localhost:8080\n```\n\nBuild an url:\n\n```js\n// 'false' uses 'http' instead of 'https'\nconst url = UrlBuilder.create('localhost', 8080/*, false*/)\n    .addPath('foo')\n    .addPathVariable('John Doe')\n    .addPath('bar')\n    .addQueryParam('baz', 'qux')\n    .addQueryParam('test', 123)\n    .build();\n\nconsole.log(url);\n// https://localhost:8080/foo/John Doe/bar?baz=qux\u0026test=123\n```\n\n`addPath()` does not allow spaces in the url and automatically trims the path value to prevent errors.\n\n`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`.\n\n```js\nconst url = UrlBuilder.create('localhost', 8080)\n    .addPath('example')\n    // 'true' will trim the path variable as it happens with .addPath()\n    .addPathVariable(' John/Doe '/*, true*/)\n    .addPath('operation')\n    .build();\n\nconsole.log(url);\n// https://localhost:8080/example/ John%2FDoe /operation\n```\n\n`addQueryParam()` accepts strings, numbers, booleans and objects. Objects will be converted to their JSON representation to create the url.\n\n```js\nconst obj = {\n    foo: 'bar',\n    baz: 0,\n    qux: true,\n};\nconst url = UrlBuilder.create('localhost', 8080)\n    .addPath('example')\n    .addQueryParam('myObj', obj)\n    .build();\n\nconsole.log(url);\n// https://localhost:8080/example?myObj={\"foo\":\"bar\",\"baz\":0,\"qux\":true}\n```\n\nEach `addPath()`, `addPathVariable()` and `addQueryParam()` operation creates a new UrlBuilder instance.\nThanks to immutability, paths can not be accidentally modified:\n\n```js\nconst base = UrlBuilder.create('localhost', 8080).addPath('base');\n\nconst fooUrl = base.addPath('foo');\nconst barUrl = base.addPath('bar');\n\nconsole.log(base.build());   // https://localhost:8080/base\nconsole.log(fooUrl.build()); // https://localhost:8080/base/foo\nconsole.log(barUrl.build()); // https://localhost:8080/base/bar\n```\n\nIf you already have an url, you can convert it to an UrlBuilder instance by using its constructor:\n\n```js\nconst url = new UrlBuilder(\"https://localhost:8080/my/path\");\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgturi%2Furl-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgturi%2Furl-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgturi%2Furl-builder/lists"}