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

rize/uri-template

RFC 6570 URI Template implementation for PHP. Expand templates into URLs and extract variables from matching URIs. Supports all expression types/levels, path segment and query expansions, plus base URI and default parameters—handy for building API endpoints.

View on GitHub
Deep Wiki
Context7

PHP URI Template (RFC 6570) supports both URI expansion & extraction

Frequently asked questions about Uri Template
How do I install rize/uri-template in a Laravel project?
Run `composer require rize/uri-template` in your Laravel project directory. The package has no Laravel-specific dependencies and integrates seamlessly with Composer. Ensure your project uses PHP 8.1+ for compatibility with the latest version.
Can I use this package to generate dynamic API URLs in Laravel controllers?
Yes. Use `UriTemplate::expand()` to generate URLs from templates with variables. For example, `$uri->expand('/users/{id}', ['id' => 123])` produces `/users/123`. This is ideal for API responses, redirects, or HTTP client requests in Laravel.
Does this package support Laravel’s route parameter extraction?
No, but it complements Laravel’s routing. Use `extract()` to validate incoming URIs against templates (e.g., in middleware) or generate URLs for external APIs. For Laravel’s built-in route parameters, use `Route::parameters()` or `request()->route()`.
What Laravel versions does rize/uri-template support?
The package requires PHP 8.1+, which aligns with Laravel 9+. For Laravel 8.x or older, you’ll need to use an older version of the package (pre-0.4.0) or a PHP polyfill, though this may introduce compatibility risks.
How can I validate incoming URIs in Laravel using this package?
Use `UriTemplate::extract()` with strict mode to validate URIs against templates. For example, in middleware, check if `request()->getUri()` matches your template. This is useful for rejecting malformed API requests early in the request lifecycle.
Are there performance concerns when using this package in Laravel’s request pipeline?
The package is lightweight, but test under load if used in high-traffic middleware or controllers. Benchmark URI expansion/extraction in your Laravel environment, especially for API endpoints with templated paths or query parameters.
Can I use this package with Laravel’s HTTP client (Guzzle) for API calls?
Absolutely. Replace hardcoded URLs in `Http::get()` or `Http::post()` with templated URIs. For example, `$uri->expand('https://api.example.com/{endpoint}', ['endpoint' => 'users'])` generates the full URL dynamically.
Does the package handle complex URI templates like nested arrays or optional segments?
Yes, it supports RFC 6570’s full spec, including nested arrays (e.g., `{list*,}`) and optional segments (e.g., `{segment}`). Test edge cases like `list[]=a&list[]=b` in Laravel’s query parameters to ensure compatibility with your use case.
What are the alternatives to rize/uri-template for Laravel?
For URI templating, consider Laravel’s built-in `Str::of()` or `Route::url()` for simple cases. For RFC 6570 compliance, alternatives like `php-uri-template` (older) or custom logic may exist, but `rize/uri-template` is the most RFC-compliant and actively maintained option.
How do I handle base URIs and default parameters in Laravel with this package?
Initialize `UriTemplate` with a base URI and defaults: `$uri = new UriTemplate('https://api.example.com/{version}', ['version' => 'v1']);`. Then expand relative paths like `/users/{id}`. This is ideal for Laravel API clients where base URLs are reused across endpoints.
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.
terminal42/code-quality-tools
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