Skip to content

y9v/cities-api

Repository files navigation

Cities service

Circle CI

This service contains basic information about cities, and provides auto-suggestion based on the city names.

Information about the cities is taken from the geonames.org dump.

Alternate names are taken for all supported locales (if given in the dump), as well as all official names.

This application uses the Gin framework, and Bolt DB.

Configuration

Option Description Default
Port On which port the server is running 8080
Timeout Server timeout, in seconds 5
CORSOrigins The list of CORS origins http://localhost
Locales The list of locales to support en
MinPopulation Lower limit for the population 2000
CountriesFile Filename to the countries dump data/countryInfo.txt
CitiesFile Filename to the cities dump data/cities.txt
AlternateNamesFile Filename to the alternate names dump data/alternateNames.txt

API

GET application/status

Returns the application status and basic statistics.

Resourse URL:

/1.0/application/status

Example result:

{
  "meta": {
    "status": "ok",
    "countries_count": 250,
    "cities_count": 145314,
    "city_names_count": 224695
  }
}

GET cities/:id

Returns a single city by the requested ID parameter.

Resourse URL:

/1.0/cities/:id

Parameters:

Parameter Requirement Description
id required The numerical ID of the desired city.

Example result:

{
  "data": [
    {
      "type": "cities",
      "id": 3164603,
      "attributes": {
        "name": "Venice",
        "country_code": "IT",
        "population": 51298,
        "timezone": "Europe/Rome",
        "latitude": 45.43713,
        "longitude": 12.33265
      },
      "links": {
        "self": "http://localhost:8082/1.0/cities/3164603"
      }
    }
  ]
}

GET cities

Returns 5 matching cities, sorted by population.

If there are several matching citynames for one city, the first one is taken based on the locale priority.

If there are cities with identical names in the search results, the country name is added to the city.

Resourse URL:

/1.0/cities

Parameters:

Parameter Requirement Description
q required A string query.

Example result:

{
  "data": [{
    "type": "cities",
    "id": 3164603,
    "attributes": {
      "name": "Venice",
      "population": 51298,
      "timezone": "Europe/Rome",
      "latitude": 45.43713,
      "longitude": 12.33265
    },
    "links": {
      "self": "http://localhost:8082/1.0/cities/3164603"
    }
  },
  {
    "type": "cities",
    "id": 4176380,
    "attributes": {
      "name": "Venice, United States",
      "population": 20748,
      "timezone": "America/New_York",
      "latitude": 27.09978,
      "longitude": -82.45426
    },
    "links": {
      "self": "http://localhost:8082/1.0/cities/4176380"
    }
  },
  {
    "type": "cities",
    "id": 4176387,
    "attributes": {
      "name": "Venice Gardens",
      "population": 7104,
      "timezone": "America/New_York",
      "latitude": 27.07311,
      "longitude": -82.4076
    },
    "links": {
      "self": "http://localhost:8082/1.0/cities/4176387"
    }
  }]
}

Make commands

To install dependencies:

make setup

To get the dumpfiles:

make getdumpfiles

Before committing:

make test

To build and run the docker instance:

make dockerrun

License

Copyright (c) 2015 Yury Lebedev

This project is released under the MIT License.

About

Small API for cities, based on geonames.org data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published