shibuyakosuke/laravel-valuedomain-api
Installation
composer require shibuyakosuke/laravel-valuedomain-api
Publish the config file:
php artisan vendor:publish --provider="ShibuyaKosuke\ValueDomainApi\ValueDomainApiServiceProvider" --tag="config"
Configuration
Edit .env with your ValueDomain API credentials:
VALUEDOMAIN_API_KEY=your_api_key_here
VALUEDOMAIN_API_SECRET=your_api_secret_here
First Use Case Fetch domain availability in a controller:
use ShibuyaKosuke\ValueDomainApi\Facades\ValueDomainApi;
public function checkDomainAvailability(Request $request)
{
$domain = $request->input('domain');
$result = ValueDomainApi::checkDomain($domain);
return response()->json($result);
}
config/valuedomain-api.php (API endpoints, defaults)src/Facades/ValueDomainApi.php (Facade for quick access)src/ValueDomainApiManager.php (Core logic)// Basic check
$isAvailable = ValueDomainApi::checkDomain('example.com');
// With callback for async handling
ValueDomainApi::checkDomain('example.com', function ($response) {
// Handle response
});
$pricing = ValueDomainApi::getDomainPricing('example.com');
$domains = ['example1.com', 'example2.com'];
$results = ValueDomainApi::checkDomains($domains);
// Dispatch a job for async domain checks
CheckDomainJob::dispatch('example.com');
Caching Responses: Cache API responses to reduce calls:
$cacheKey = "valuedomain_{$domain}";
if (Cache::has($cacheKey)) {
return Cache::get($cacheKey);
}
$result = ValueDomainApi::checkDomain($domain);
Cache::put($cacheKey, $result, now()->addHours(1));
Error Handling: Wrap API calls in try-catch:
try {
$result = ValueDomainApi::checkDomain('example.com');
} catch (\Exception $e) {
Log::error("ValueDomain API Error: " . $e->getMessage());
return response()->json(['error' => 'Service unavailable'], 503);
}
Rate Limiting: Use Laravel’s throttle middleware if the API has rate limits.
API Key Exposure
.env is in your .gitignore. Avoid hardcoding keys in config files.Rate Limits
429 Too Many Requests.Deprecated Endpoints
No Built-in Retry Logic
use Illuminate\Support\Facades\Http;
Http::retry(3, 100)->post(...);
Enable Debug Mode
Set debug to true in config/valuedomain-api.php to log raw API responses:
'debug' => env('VALUEDOMAIN_DEBUG', false),
Check HTTP Client The package uses Laravel’s HTTP client. Inspect requests with:
php artisan route:list
or use a tool like Postman to verify endpoints manually.
Custom Responses
Override the default response handling by extending ShibuyaKosuke\ValueDomainApi\ValueDomainApiManager:
class CustomValueDomainApiManager extends ValueDomainApiManager
{
public function checkDomain($domain)
{
$response = parent::checkDomain($domain);
// Transform response here
return $this->customTransform($response);
}
}
Add New Endpoints
Extend the makeRequest method to support additional API routes:
public function getNewEndpoint($param)
{
return $this->makeRequest('GET', '/new-endpoint', ['param' => $param]);
}
Mocking for Tests Use Laravel’s HTTP mocking in tests:
Http::fake([
'api.valuedomain.com/*' => Http::response(['available' => true]),
]);
How can I help you explore Laravel packages today?