Skip to content
🌎 Geodata API - Get countries, and cities in a country to plug in a select drop-down.
PHP HTML Hack
Branch: master
Clone or download

README.md

Country City API

Build Status Code Climate codecov License Support me on Patreon Support me on Paypal Get Help on codementor

This is geodata API built to get the data with countries in the world and cities in a particular country. This API is a plugin for creating drop-downs in a form which populate via an AJAX request. You can find a select2 implementation here. Code for this implementation is in example directory.

⚡️ Installing the CountryCity API

  • 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.

#️⃣ API Endpoints

All API responses are in json format.

  • Get all countries
/countries

# Without URL Rewriting
/index.php/countries
  • Get all cities in a country
/cities/{countryName}

# Without URL Rewriting
/index.php/cities/{countryName}

Rest API Features

  • Built using Slim micro framework.
  • Caching enabled with following headers
    • ETag
    • Expires
    • Last-Modified
  • Fast and lightweight API
  • PSR 7 Complaint

☁️ Hosting configuration

Here are the Configuration Instructions if you want to host this on your server.

🔧 Error Format

If there is an error in the API, you will get an error in json format as response

{"error":"true", "message": "error message here"}

🚨 Testing

$ vendor/bin/phpunit --configuration phpunit.xml.dist

📜 License

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

Contributions are welcome! See Contributor's Guide.

💖 Support this project

  • Please star the project and share it among your developer friends.
  • Consider supporting on Support me on Patreon and Support me on Paypal.
You can’t perform that action at this time.