Download the PHP package unirate/slim without Composer
On this page you can find all versions of the php package unirate/slim. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package slim
Short Description Slim Framework 4 integration for the UniRate API — a framework-agnostic PSR-18 client, PSR-15 middleware, and ready-made JSON routes for currency exchange rates, conversion, currencies, and VAT.
License MIT
Homepage https://github.com/UniRate-API/slim-unirate
Informations about the package slim
UniRate for Slim
A Slim Framework 4 integration for the UniRate API — live currency exchange rates, conversion, supported-currency lists, and VAT rates.
It ships three pieces you can use together or separately:
UniRate\Slim\UniRateClient— a framework-agnostic client built on PSR-18 (HTTP client) and PSR-17 (request/URI factories), so it works with any HTTP client (Guzzle, Symfony HttpClient, …) and is trivial to mock.UniRate\Slim\UniRateMiddleware— PSR-15 middleware that attaches the client to the request as an attribute.registerUniRateRoutes()— a helper that adds ready-made JSON routes (/rate,/convert,/currencies,/vat) to your Slim app.
Installation
You also need a PSR-18 HTTP client and PSR-17 factories. For example, with Guzzle:
Get a free API key at unirateapi.com.
Quick start
See examples/app.php for a complete runnable server.
Configuration
UniRateConfig takes the API key and an optional base URL, or build it from an
options array:
Routes
registerUniRateRoutes($app, $prefix = '/unirate', ?UniRateClient $client = null)
registers four GET routes returning JSON:
| Route | Query params | Response |
|---|---|---|
{prefix}/rate |
from (default USD), to (optional) |
{"rate": 0.92} or {"rate": {"EUR": 0.92, …}} |
{prefix}/convert |
from (default USD), to (required), amount (default 1) |
{"result": 92.5} |
{prefix}/currencies |
— | {"currencies": ["USD", "EUR", …]} |
{prefix}/vat |
country (optional) |
{"vat": {…}} |
Route handlers resolve the client from the request attribute set by
UniRateMiddleware. If you prefer not to use the middleware, pass the client as
the third argument to make the routes self-contained:
Using the client directly
Inside a Slim handler, resolve the client from the request attribute:
Error handling
The client throws UniRate\Slim\UniRateException (base), with the HTTP status as
the exception code. Typed subclasses let you catch specific failures:
| Status | Exception | Meaning |
|---|---|---|
| 400 | Exception\InvalidDateException |
Invalid request parameters |
| 401 | Exception\AuthenticationException |
Missing or invalid API key |
| 403 | Exception\ApiException |
Endpoint requires a Pro subscription |
| 404 | Exception\InvalidCurrencyException |
Currency not found or no data available |
| 429 | Exception\RateLimitException |
Rate limit exceeded |
| 503 | Exception\ApiException |
Service unavailable |
| other | Exception\ApiException |
Generic API error (status + body) |
The registered routes map these to JSON error responses that mirror the API
status, e.g. 429 → {"error": "Rate limit exceeded."}.
Historical endpoints (getHistoricalRate) are Pro-gated and return 403
on the free tier.
Rate limits
Free-tier keys are rate limited; a 429 surfaces as RateLimitException.
Testing
The suite mocks all HTTP traffic via php-http/mock-client —
no live API calls or key required.
License
MIT — see LICENSE.
Related clients
Part of the official UniRate client family: Python, Node/TypeScript, Swift, Java, Go, Rust, Ruby, PHP, and .NET, plus framework integrations for Laravel, Symfony, Statamic, WordPress, and more.
All versions of slim with dependencies
slim/slim Version ^4.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0