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

rize/uri-template

PHP implementation of RFC 6570 URI Templates with full support for all expression types and levels. Expand templates with variables, path segments, and more, plus extract variables from URIs. Supports base URIs and default params for clean API endpoint building.

View on GitHub
Deep Wiki
Context7

rize/uri-template is a PHP implementation of RFC 6570 URI Templates, supporting both URI expansion and extraction. It is used by Google Cloud libraries and handles all RFC-defined expression types and levels.

  • Full RFC 6570 expansion and extraction support
  • Path segment and extension expansion ({/segments*}, {.extensions*})
  • Base URI and default parameter handling for API endpoints
  • Query parameter expansion with arrays and limits
  • Compatible with modern PHP versions (8.1+)
Frequently asked questions about Uri Template
Does rize/uri-template work with Laravel 10 and Laravel 11?
Yes. The 0.4.x line requires PHP 8.1 or newer, which aligns with the Laravel 10 and Laravel 11 baselines. A Laravel 9 estate still on PHP 8.0 is blocked unless you pin the older 0.3.x branch, which no longer receives modernization work and produces PHP 8.4 deprecation noise. Constrain an exact minor such as ^0.4.2 so you are not silently stranded.
How do I install rize/uri-template with Composer?
Run composer require rize/uri-template and constrain it to ^0.4.2 or an exact 0.4.x. Be aware that the README install snippet still shows ~0.3, which is stale and would pin you to the pre-8.1 branch. There are no assets to publish, no migrations, and no configuration step.
What PHP version does rize/uri-template require?
Version 0.4.0 and later requires PHP 8.1 or higher, because explicit nullable parameter types were added for PHP 8.4 compatibility. The 0.3.x line supported PHP 8.0 and below but is effectively frozen. Check the constraint before upgrading a legacy application.
How is rize/uri-template different from Laravel's route() and url() helpers?
Laravel's route() and url() reverse registered routes into plain URLs and cannot express RFC 6570 operators like {/segments*}, {.extensions*}, or {?q*,limit}. rize/uri-template supports all expression types and levels, including path segment and query string expansion, which is what you need when building third-party API endpoints that do not exist in your router. It also provides extraction, for which the framework has no equivalent.
Can rize/uri-template extract variables from an incoming URI?
Yes. extract() matches an arbitrary runtime template string against an inbound URI and returns the captured variables, something the Laravel router cannot do because it only matches registered routes. Use strict mode for validation-sensitive paths, since non-strict extraction returns an array of null values rather than failing and a caller can mistake that truthy result for a match. Treat the output as parsed data, never as an authorization decision.
Do I need a service provider or config file to use rize/uri-template in Laravel?
No. It is a dependency-free, framework-agnostic library with a two-method public surface, expand() and extract(), and it ships no service provider, facade, config file, or publishable assets. In Laravel you simply require it and optionally bind a thin wrapper class in the container. That also means there is nothing to own or migrate when you upgrade the framework.
How do I use a base URI and default parameters for API endpoint building?
Pass the base URI as the first constructor argument and default params as the second, then expand relative templates against them. For example, new UriTemplate('https://api.twitter.com/{version}', ['version' => 1.1]) followed by expand('/statuses/show/{id}.json', ['id' => $id]) produces a complete endpoint URL. This keeps version prefixes and shared defaults out of every call site.
Is rize/uri-template safe for validating untrusted URIs?
Treat extraction as parsing, not as a security control. Extraction is regex-based string parsing over untrusted input, and the official spec conformance suite does not fuzz for pathological backtracking or hostile URIs. Strict mode helps reject non-conforming input, but you should still validate and authorize the extracted values after the match rather than relying on the template alone.
Is rize/uri-template actively maintained and production ready?
It is pre-1.0 and has already shipped a breaking change, with 0.3.x to 0.4.0 altering the internal type system and dropping support for PHP below 8.1. The README states it is consumed by google-cloud-php-core and the Google Cloud client libraries, though Packagist dependent counts are unreliable, so verify the constraint directly in that package's composer.json before citing it as a durability argument. Pin an exact minor and require human review on minor bumps via Renovate or Dependabot.
Are there alternatives to rize/uri-template for RFC 6570 in PHP?
Guzzle shipped an older RFC 6570 implementation and several small packages exist, but rize/uri-template is one of the few PHP libraries covering full expansion with every expression type plus extraction. If you only need simple placeholder substitution, Laravel's string helpers or a hand-rolled replacement may be enough and remove the dependency entirely. For spec-complete behavior, evaluate the library against the official uritemplate-test suite before adopting it.
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.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin