Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hamedhaghi/countries-client
The REST Countries API client for PHP.
https://github.com/hamedhaghi/countries-client
composer package php
Last synced: 3 days ago
JSON representation
The REST Countries API client for PHP.
- Host: GitHub
- URL: https://github.com/hamedhaghi/countries-client
- Owner: hamedhaghi
- License: mit
- Created: 2024-11-28T13:03:01.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-12-21T17:35:58.000Z (about 1 month ago)
- Last Synced: 2025-01-20T23:48:19.256Z (4 days ago)
- Topics: composer, package, php
- Language: PHP
- Homepage: https://packagist.org/packages/hamedhaghi/countries
- Size: 122 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Countries PHP Client
A PHP client for the [RestCountries API](https://restcountries.com/). This package simplifies interacting with the API by providing an object-oriented interface to retrieve country data.
## Features
- Fetch detailed information about countries.
- Support for caching to improve performance.
- Compatible with both legacy and modern PHP projects.## Requirements
- PHP 7.0 or higher
## Installation
Install the package via Composer:
```bash
composer require hamedhaghi/countries
```## Usage Example
```php
require_once 'vendor/autoload.php';use Hamed\Countries\Factory\CountryRepositoryFactory;
// Initialize the client
$factory = new CountryRepositoryFactory();// Enable caching for faster responses (optional)
$factory = $factory->isCachable()
->setCacheTTL(3600); // Cache expiration time in seconds// Initialize the repository
$repository = $factory->init();// Query country data
$countries = $repository->getAll();
$countries = $repository->getByCapital('Berlin');
$countries = $repository->getByCode('DE');
$countries = $repository->getByCurrency('euro');
$countries = $repository->getByDemonym('German');
$countries = $repository->getByFullName('Germany');
$countries = $repository->getByLanguage('German');
$countries = $repository->getByName('Germany');
$countries = $repository->getByRegion('Europe');
$countries = $repository->getBySubregion('Western Europe');
$countries = $repository->getByTranslation('Germany');// Clear the cache
$factory->clearCache();```
## Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
## License
This project is licensed under the MIT License.