Locations API

Brief guide on how to use the API.


This application provides API which includes fetching lists of Countries,Continents,States etc in the form of json response. Only Get requests are accepted by this API. To use the API, you must be authenticated using the token provided at the dashboard.

  1. Sign up using Github or Registration form provided at the footer of every page.
  2. Login to the application and click on User icon link on the navbar.
  3. Click on Get Token option to generate your API token.
  4. Copy the token from the alert popped up and use it to access the API.
  5. In few mobile browsers, this alert does not pop up. In that case, use a PC.
  6. Below given are url examples for each response provided by the API.
  • Please note :
  • The response is in json format
  • Your API token must be provided in the Header of the GET request.
  • Id mentioned in the sample urls must be replaced by the object's ID which is provided by the application.
  • Any method other than GET such as POST,PUT & DELETE etc. is not allowed.

Get the list of all continents Sample response

https://python.vishnusayanth.com/api/continents/

Get the list of all countries Sample response

https://python.vishnusayanth.com/api/countries/

Get the list of states in country with id 1 Sample response

https://python.vishnusayanth.com/api/states/1

Get the list of countries in continent with id 1 Sample response

https://python.vishnusayanth.com/api/countries_in_continent/1

Get the capital of country with id 1 Sample response

https://python.vishnusayanth.com/api/capital/1

  • Here is an example of how to use this API to get a list of continents using Python script.
    import requests

    url = 'https://python.vishnusayanth.com/api/continents/'
    headers = {'Authorization':'Token <your_api_token_here>'}
    response = requests.get(url=url,headers=headers)
    jsonData = response.json()

    # Play around with jsonData
  • <html>
      <head>
        <script src=" < jQuery_source_url_here >"></script>
        <script>
          let url = 'https://python.vishnusayanth.com/api/countries/';
          let headers = {'Authorization': 'Token <your_api_token_here>'};
          $(document).ready(function () {
            $.ajax({
              type: "GET",
              dataType: "json",
              headers: headers,
              url: url,
              success: function (data) {
                $.each(data.countries, function (i, item) {
                let opt_string = '<option value=' + item.name + '>'
                 + item.name + '</option>'
                $('#mySelect').append(opt_string);
                });
              }
            });
          });
        </script>
      </head>
    <body>
      <select id="mySelect">
        <option value="">Select Country</option>
      </select>
    </body>
    </html>

Features

Check out what's possible on this application.


This is a hobby project developed by Vishnu Sayanth, deployed on Heroku platform. This application has a public API that can be used to get data on geographic locations like countries,continents & states etc. Below given are the things possible on this applciation.


Technology

Technologies & Tools used to build this app.


This application is built using the Python framework, Django. The front end is developed using HTML5, CSS3 & Javascript and Python is used as the backend, obviously. Jquery & AJAX are used for asynchronous tasks such as sending emails and other stuff. The CSS framework Bootstrap is used to style the front end of the application. Locations API is developed using Django REST framework which accesses data in a PostgreSQL database. API provided by Spotify & data scraped off of Google News is also utilised in this application.
The application is versioned and deployed using the continuous deployment provided by Heroku & GitHub. The source code of this application can be found here.