PHPackages                             juststeveking/uri-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. juststeveking/uri-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

juststeveking/uri-builder
=========================

A simple URI builder in PHP that is slightly opinionated

3.0.0(3y ago)20285.7k↑22%7[1 issues](https://github.com/JustSteveKing/uri-builder/issues)[1 PRs](https://github.com/JustSteveKing/uri-builder/pulls)5MITPHPPHP ^8.1

Since Oct 11Pushed 3y agoCompare

[ Source](https://github.com/JustSteveKing/uri-builder)[ Packagist](https://packagist.org/packages/juststeveking/uri-builder)[ GitHub Sponsors](https://github.com/JustSteveKing)[ RSS](/packages/juststeveking-uri-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (13)Used By (5)

[![](./uri-builder.png)](./uri-builder.png)

URI Builder
===========

[](#uri-builder)

[![Latest Version](https://camo.githubusercontent.com/17690b0e39ea0c58dc9f9be0361de7b7533d76535260c095c38f7f333b3b06ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f7572692d6275696c6465722e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/juststeveking/uri-builder)[![PHP Version](https://camo.githubusercontent.com/dccf13bb779482367523d715bdb9a7943f075f285b221751bcea9f4ec2729d97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a75737473746576656b696e672f7572692d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![tests](https://github.com/JustSteveKing/uri-builder/workflows/tests/badge.svg)](https://github.com/JustSteveKing/uri-builder/workflows/tests/badge.svg)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5dccbc9d5eeca11df22316ea06e58e7013cf0f880565284f99daced268efebd6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a75737453746576654b696e672f7572692d6275696c6465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/JustSteveKing/uri-builder/?branch=main)[![Total Downloads](https://camo.githubusercontent.com/817fe3a4e6c8a8c4b691f35326693f1af83c58457c93a2b2b299136f60ea1289/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f7572692d6275696c6465722e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/juststeveking/uri-builder)

A simple URI builder in PHP that is slightly opinionated

Purpose
-------

[](#purpose)

The purpose of this package is to provide a fluent interface to build JSON:API compliant URI strings.

Usage
-----

[](#usage)

Using the built in `parse_url` in PHP will produce the following output:

```
[
    "scheme" => "https",
    "host" => "www.domain.com",
    "path" => "/api/v1/resource"
    "query" => "include=test,another&sort=-name",
]
```

This is fine for basic usage. To use this very opinionated package:

### Building Pragmatically

[](#building-pragmatically)

```
$url = Uri::build()
           ->addScheme('https')
           ->addHost('www.domain.com')
           ->addPath('api/v1/resource')
           ->addQuery('include=test,another&sort=-name')
           ->addFragment('static-link-to-element');
```

### Creating from a String

[](#creating-from-a-string)

```
$url = Uri::fromString('https://www.domain.com/api/v1/resource?include=test,another&sort=-name')
```

### Converting back to a String

[](#converting-back-to-a-string)

```
$url = Uri::build()
           ->addScheme('https')
           ->addHost('www.domain.com')
           ->addPath('api/v1/resource')
           ->addQuery('include=test,another&sort=-name');

$string = $url->toString();

// optionally
echo (string) $url;
```

The `toString` method has an optional parameter which will allow you to urlencode the query parameters before returning the URI.

```
$url = Uri::build()
           ->addScheme('https')
           ->addHost('www.domain.com')
           ->addPath('api/v1/resource')
           ->addQuery('include=test,another&sort=-name');

$string = $url->toString(true)
```

### Adding Query Parameters after creation

[](#adding-query-parameters-after-creation)

Creating query parameters after creation is pretty simple. You can pass through anything that isn't:

- An Object
- An Array

It has a helper option on the end of the function which will convert booleans to strings.

```
public function addQueryParam(string $key, $value, bool $covertBoolToString = false)
```

The following is how you use it:

```
$url = Uri::fromString('https://www.domain.com/api/v1/resource');
$url->addQueryParam('include', 'test,another,options')
    ->addQueryParam('published', true, true);
```

The output will be: `https://www.domain.com/api/v1/resource?include=test,another,options&published=true`

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 76.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~158 days

Total

12

Last Release

1404d ago

Major Versions

v0.9.1 → v1.0.02020-10-12

v1.1.0 → 2.0.02021-07-08

2.0.0 → 3.0.02022-07-15

PHP version history (4 changes)v1.0.3PHP ^7.4

v1.1.0PHP ^7.4|^8.0

2.0.0PHP ^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a87fe82b349821ebd49cf57d65c4cd3e33ae0833222a8438d90fe8921ca899ea?d=identicon)[JustSteveKing](/maintainers/JustSteveKing)

---

Top Contributors

[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (36 commits)")[![BinaryKitten](https://avatars.githubusercontent.com/u/67553?v=4)](https://github.com/BinaryKitten "BinaryKitten (11 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juststeveking-uri-builder/health.svg)

```
[![Health](https://phpackages.com/badges/juststeveking-uri-builder/health.svg)](https://phpackages.com/packages/juststeveking-uri-builder)
```

###  Alternatives

[droptica/droopler

Droopler - SEO Friendly CMS &amp; Site Builder - is a Drupal-based website builder that helps you create beautiful, fast, and easy-to-manage websites

6543.1k1](/packages/droptica-droopler)[facebook/facebook-for-magento

Facebook For Magento

852.0k](/packages/facebook-facebook-for-magento)[sinergi/token

PHP library to generate random strings

188.7k9](/packages/sinergi-token)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
