-
-
Notifications
You must be signed in to change notification settings - Fork 51
Home
Shivam Mathur edited this page May 19, 2020
·
3 revisions
Geodata API to get the list of countries and cities in the world. This can be plugged in country and city picker drop-downs in forms. You can find a select2 implementation here. Code for this implementation is in example
directory.
- Make sure you have PHP 7.4 or newer.
- Download this API using composer using the command below.
$ composer global require shivammathur/countrycity "master-dev"
- Then install the API using by executing the command below.
$ composer create-project shivammathur/countrycity countrycity "master-dev" --prefer-dist
- You are all set, you can use this API.
All API responses are in json
format.
- Get all countries
/countries
# Without URL Rewriting
/index.php/countries
- Get all countries containing a search keyword
/countries/{search_keyword}
# Without URL Rewriting
/index.php/countries/{search_keyword}
- Get all cities in a country
/cities/{country}
# Without URL Rewriting
/index.php/cities/{country}
- Get all cities in a country containing a search keyword
/cities/{country}/{search_keyword}
# Without URL Rewriting
/index.php/cities/{country}/{search_keyword}
- Built using Slim micro framework.
- Caching enabled with following headers
- ETag
- Expires
- Last-Modified
- Fast and lightweight API
- PSR 7 Complaint
Here are the Configuration Instructions if you want to host this on your server.
If there is an error in the API, you will get an error in json
format as response
{"error":"true", "message": "error message here"}
$ vendor/bin/phpunit --configuration phpunit.xml.dist
The scripts and documentation in this project are released under the MIT License. This project has multiple dependencies and their licenses can be found in their respective repositories.
Contributions are welcome! See Contributor's Guide.