Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Uri Template

Uri Template Laravel Package

guzzlehttp/uri-template

Expands RFC 6570 URI templates into concrete URI strings in PHP, turning templates like /users/{id}{?tab} into real paths with query strings from an array of values.

View on GitHub
Deep Wiki
Context7

guzzlehttp/uri-template expands RFC 6570 URI templates in PHP, turning templates like /users/{id}{?tab} into concrete URI strings from an array of variables. It's the standalone expansion engine behind Guzzle, useful whenever an API describes paths or links with URI templates.

  • Implements RFC 6570 expansion, including query and path operators
  • Simple static API: UriTemplate::expand($template, $variables)
  • PHP >=7.4,<8.6 for 2.0, with a maintained 1.0 line
  • Ships with usage, input-contract, and upgrade guides
Frequently asked questions about Uri Template
How do I install guzzlehttp/uri-template in a Laravel application?
Run composer require guzzlehttp/uri-template in the root of your Laravel project. There is no service provider, configuration file, migration, or environment variable to publish. Because guzzlehttp/guzzle often already pulls it in transitively, check composer.lock first and add a direct requirement only when your application code uses UriTemplate itself.
Which Laravel and PHP versions support guzzlehttp/uri-template?
Version 2.0 requires PHP 7.4 or newer and supports PHP up to below 8.6, so it works with Laravel releases running on those PHP versions, including modern Laravel 9, 10, 11, and 12 applications. The package is framework-agnostic and has no Laravel-specific version constraints. Version 1.0 is in maintenance mode for older PHP 7.2.5+ projects. Always confirm the PHP constraint against your app's composer.json.
Do I need to register a service provider or publish config for guzzlehttp/uri-template?
No. guzzlehttp/uri-template is a leaf utility with a static expansion API, not a Laravel package with a service provider. You can call GuzzleHttp\UriTemplate\UriTemplate::expand() directly from controllers, jobs, services, or HTTP client code. If you want dependency injection or test seams, wrap it in your own small service class.
What Laravel use cases fit RFC 6570 URI templates?
Use it wherever an API describes links or paths as templates: third-party API endpoints, pagination link headers, webhook and callback URLs, signed URL bases, deep links in emails or notifications, and multi-tenant subdomain or tenant-in-path routing. It replaces fragile sprintf concatenation and http_build_query ladders with standards-defined expansion. It is especially useful when the template comes from an external API specification.
How do I expand a template like /users/{id}{?tab} with query parameters?
Call UriTemplate::expand('/users/{id}{?tab}', ['id' => 123, 'tab' => 'settings']) and the result is /users/123?tab=settings. The variable names in the array must match the names in the template, and missing values are omitted according to RFC 6570 rules. You can use operators such as {?fields,limit} for query strings and {/segments*} for path segments.
Is guzzlehttp/uri-template a replacement for Laravel's route() or url() helpers?
No. It is not a router, URL builder, query-string merger, or validation layer, and it does not replace route(), url(), or Laravel's HTTP client. It only expands RFC 6570 templates into URI strings. It also has no connection to Eloquent or Laravel's query builder where() operators, despite some misattributed notes about SQL operator handling.
How should I handle security when expanding user input with URI templates?
Treat template strings as trusted configuration or code, and never let users control the template itself. For untrusted values, prefer simple or path-segment operators such as {id} or {/segment} and avoid reserved expansions like {+var} and {#var}, which deliberately preserve reserved characters and existing percent-encoded triplets. That policy reduces path traversal, query injection, and open-redirect shaping risks. Validate and constrain values before expansion as you would for any outbound URL.
How do I test URI template expansion in a Laravel test suite?
Write PHPUnit or Pest tests that assert the exact expanded URI for each template and value set, including empty values, arrays, nested query parameters, and reserved characters. Run those tests after every Composer update because the 1.0.x and 2.0.x release trains have included edge-case fixes for empty expansions, nested arrays, and encoding. The package's own test suite runs with make test in its repository. Pin a minor version and re-run expansion tests on patch bumps.
What are the alternatives to guzzlehttp/uri-template in Laravel?
For simple cases you can use Laravel's url() and route() helpers, string concatenation, or http_build_query, but those do not implement RFC 6570. Other PHP options include rize/uri-template and league/uri components, depending on whether you need broader URI manipulation. guzzlehttp/uri-template is attractive when you want a small, MIT-licensed, Composer-only dependency that is often already present via Guzzle.
Is guzzlehttp/uri-template production-ready and how should I manage updates?
Yes, it is a small, widely used, MIT-licensed Guzzle package with a stable happy path for common templates. The main production caveats are encoding semantics for reserved expansions and recent edge-case churn in complex expansions, so pin the minor version and re-run your URL tests on every patch bump. Maintainer support is effectively single-vendor under the Guzzle project with Tidelift backing, and version 2.0 is the current line while 1.0 remains in maintenance.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings