Weave Code
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

RFC 6570 URI Template expansion for PHP. Build URLs by substituting variables into templates, handling reserved characters, query strings, and fragments. Lightweight Guzzle component installable via Composer, with tests and changelog included.

View on GitHub
Deep Wiki
Context7

Expands RFC 6570 URI templates

Frequently asked questions about Uri Template
How do I install guzzlehttp/uri-template in a Laravel project?
Run `composer require guzzlehttp/uri-template` in your project root. The package is PSR-4 compliant, so Laravel’s autoloader will handle dependencies automatically. No additional configuration is needed for basic usage.
Does this package work with Laravel’s HTTP client (e.g., Http::get())?
Yes, it integrates seamlessly with Laravel’s HTTP client. Use it to dynamically construct URLs with templated parameters, like `Http::get($uriTemplate, ['var' => $value])`, where `$uriTemplate` is expanded using this package.
What Laravel versions does guzzlehttp/uri-template support?
The package itself has no Laravel-specific dependencies, so it works with any Laravel version that supports PHP 7.2+. However, ensure your Laravel app’s PHP version (e.g., 8.1+) aligns with the package’s requirements (check the [README](https://github.com/guzzle/uri-template)).
How does this handle empty-string variables in URI templates (e.g., ?{+var} where var is empty)?
From v1.0.7, empty-string expansion may alter query semantics (e.g., `?+filter=` instead of `?filter=`). Test your use cases—especially if using operator prefixes like `+`, `&`, or `|`—to confirm behavior matches expectations. Adjust templates or logic if needed.
Will this package trigger PHP 8.5 warnings for non-finite floats (e.g., INF, NAN)?
Yes, PHP 8.5+ will warn for non-finite floats like `INF` or `NAN` in URI templates. Suppress warnings with `@` (e.g., `@$template->expand(['limit' => INF])`) or update error handling to filter out such values before templating.
Can I use this for Laravel API resource URLs or dynamic routing?
Absolutely. It’s ideal for generating API resource URLs (e.g., `/users/{id}`) or query strings with dynamic filters (e.g., `?sort={field}&limit={page}`). Pair it with Laravel’s `Route::param()` or `Http::asForm()` for seamless integration.
Are there alternatives to guzzlehttp/uri-template for Laravel?
For Laravel, alternatives include `symfony/routing` (built-in, but heavier) or `spatie/url` (simpler but less RFC-compliant). This package is lighter, RFC 6570-compliant, and integrates better with Guzzle-based HTTP tooling—ideal for API-heavy apps.
How do I test URI templates in Laravel’s test suite?
Use PHPUnit to test edge cases: mock templates with empty strings or non-finite floats, then assert expanded URLs match expectations. Example: `assertEquals('?filter=', $template->expand(['filter' => '']));`. Run tests via `make test` in the package repo for reference.
Does this package support Laravel’s route caching or model binding?
No, this package focuses on URI templating, not Laravel’s routing layer. Use it to pre-generate URLs for cached routes or model binding (e.g., `route('users.show', ['id' => $user->id])` with templated parameters).
How often is guzzlehttp/uri-template maintained, and is it safe for production?
The package is actively maintained by the Guzzle team, with a 1.0+ release series indicating stability. It’s safe for production, but review the [changelog](https://github.com/guzzle/uri-template/blob/master/CHANGELOG.md) for breaking changes (e.g., v1.0.7’s empty-string fixes). Monitor for updates if using PHP 8.5+.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor