> For the complete documentation index, see [llms.txt](https://docs.opensoutheners.com/oss/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opensoutheners.com/oss/flex-url/readme.md).

# Introduction

An immutable, fluent URL builder/parser for the apiable request-query grammar, available as a TypeScript package and a mirrored PHP package.

**Flex Url** is a zero-dependency URL builder/parser for the [Laravel Apiable](https://github.com/open-southeners/laravel-apiable) request-query grammar — `filter`, `sort`, `include`, `fields`, `appends`, `page` and `q`. It ships as two mirrored packages from a single monorepo:

* **`flex-url`** on npm — the TypeScript core, ESM + CJS, full type declarations.
* **`open-southeners/flex-url`** on Packagist — the PHP mirror, framework-free.

Method names and wire semantics are kept identical between the two on purpose, so a Vue/Inertia frontend and a Laravel backend (or a server-rendered Livewire table) speak the exact same URL grammar without translating between two different mental models.

{% tabs %}
{% tab title="TypeScript" %}

```ts
import {url} from 'flex-url';

url('https://api.example.com/posts')
  .filter('status', 'published')
  .sort('-created_at')
  .include('tags', 'author')
  .page(1)
  .toString();
// => "https://api.example.com/posts?filter[status]=published&sort=-created_at&include=tags,author&page[number]=1"
```

{% endtab %}

{% tab title="PHP" %}

```php
use function flex_url;

flex_url('https://api.example.com/posts')
    ->filter('status', 'published')
    ->sort('-created_at')
    ->include('tags', 'author')
    ->page(1)
    ->toString();
// => "https://api.example.com/posts?filter[status]=published&sort=-created_at&include=tags,author&page[number]=1"
```

{% endtab %}
{% endtabs %}

## Features

* **Immutable** — every builder call returns a *new* instance; nothing is ever mutated in place.
* **Parse = build** — constructing from a URL hydrates the exact same state a builder produces, so a URL can be round-tripped through the builder and read back with `getFilter()`, `getSorts()`, `getPage()`, and friends.
* **Full URL fidelity** — pathname, port, hash, and any existing query params are preserved.
* **Matches apiable's own encoding idiom** — brackets and commas are raw on the wire, individual values are percent-encoded. See [Encoding Contract](/oss/flex-url/advanced/encoding-contract.md).
* **Typed schemas (TypeScript)** — narrow `filter()`/`sort()`/`include()`/`fields()`/`append()` to a specific endpoint's allowed vocabulary at compile time, generated straight from apiable's `apiable:types` exporter.
* **Framework-free (PHP)** — no Laravel/Illuminate runtime dependency. `toQuery()`/`toRequestUri()` give you what you need to dispatch an in-kernel sub-request yourself.
* **Cross-language test parity** — both implementations are tested against the same [shared JSON fixtures](/oss/flex-url/testing/testing-and-parity.md), so they can't silently drift apart.

## Requirements

|              | TypeScript (`flex-url`) | PHP (`open-southeners/flex-url`) |
| ------------ | ----------------------- | -------------------------------- |
| Runtime      | Node.js 24.x or 26.x    | PHP 8.2+                         |
| Dependencies | None                    | None                             |

## Quick start

{% tabs %}
{% tab title="TypeScript" %}

```bash
npm install flex-url
```

{% endtab %}

{% tab title="PHP" %}

```bash
composer require open-southeners/flex-url
```

{% endtab %}
{% endtabs %}

Then head to the [Installation](/oss/flex-url/getting-started/installation.md) guide, or straight to [Quick Start](/oss/flex-url/getting-started/quick-start.md) for a tour of the builder API.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.opensoutheners.com/oss/flex-url/readme.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
