- How do I install and set up the AstroWay SDK in a Laravel project?
- Run `composer require astroway/sdk guzzlehttp/guzzle` to install the SDK and a PSR-18 HTTP client. Initialize the SDK with your API key in `config/services.php` or via environment variables, then bind it to Laravel’s service container if needed. The SDK auto-discovers HTTP clients via `php-http/discovery`.
- Does this SDK work with Laravel’s built-in HTTP client or only Guzzle?
- The SDK is PSR-18 compliant, so it works seamlessly with Laravel’s HTTP client, Guzzle, or any other PSR-18-compliant client. No additional configuration is required if you’re using Laravel’s default client or Guzzle.
- What Laravel versions and PHP versions are supported?
- The SDK requires PHP 8.2+, which aligns with Laravel 10+. For older Laravel versions (e.g., 9.x), use version 0.1.x of the SDK, but note that it lacks SemVer guarantees. Always check the package’s `composer.json` for exact version requirements.
- How do I handle API rate limits or retries in Laravel?
- The SDK includes built-in exponential backoff retries for HTTP 408, 409, 429, and 5xx errors. Configure retry settings via the SDK’s constructor or use Laravel’s queue system to delay retries for rate-limited requests. Log errors using PSR-3 (Laravel’s `Log` facade).
- Can I cache API responses in Laravel to reduce costs?
- Yes, the SDK supports PSR-16 caching (e.g., Redis, file cache). Configure it via the `cache` option in the SDK constructor, and use Laravel’s caching system to store responses like daily horoscopes or frequently accessed charts.
- How do I test the AstroWay SDK in Laravel?
- Use the `MockAstroway` class for unit testing to avoid hitting the real API. For HTTP tests, mock API responses using Laravel’s HTTP test helpers or tools like VCR. The SDK’s type safety makes it easy to validate responses in tests.
- What are the credit costs for common endpoints, and how can I monitor usage?
- Endpoints range from 5 to 500 credits, depending on complexity (e.g., natal charts cost ~50 credits). Monitor usage via the `creditsRemaining` field in responses or implement Laravel middleware to track credit consumption. AstroWay offers 10,000 free credits/month.
- How do I integrate this SDK with Laravel’s service container?
- Bind the SDK as a singleton or context-bound service in `AppServiceProvider`. Example: `app()->bind(Astroway::class, fn() => new Astroway(['apiKey' => config('services.astroway.api_key')]))`. This ensures dependency injection across Laravel’s components.
- Are there alternatives to this SDK for astrology APIs in Laravel?
- AstroWay’s SDK is the official, type-safe, and PSR-compliant choice for their API. Alternatives like third-party astrology libraries (e.g., PHP-Astrology) lack AstroWay’s breadth (Tarot, Numerology, AI horoscopes) or modern tooling. For custom APIs, consider building a lightweight wrapper around Guzzle.
- How do I handle errors like authentication failures or invalid requests in Laravel?
- The SDK throws typed exceptions (e.g., `AuthenticationError`, `RateLimitError`). Catch these in Laravel middleware or controllers to provide user-friendly messages. Log errors using PSR-3 (Laravel’s `Log` facade) for debugging, and implement retry logic for transient failures.