Giter VIP home page Giter VIP logo

countrycity's Introduction

Country City API

Build Status Code Climate codecov License

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.

⚡ Installing the CountryCity API

  • Make sure you have PHP 7.4 or newer.
$ php -v
  • Download this API using composer using the command below.
composer global require shivammathur/countrycity "dev-main"
  • Then install the API by executing the command below.
composer create-project shivammathur/countrycity countrycity "dev-main" --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 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}

✨ Rest API Features

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

☁️ 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 with the community.
  • Support the project by sponsoring my work on GitHub sponsors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.