Code Monkey home page Code Monkey logo

cities-api's Introduction

Cities API


Counts

{
  cities: 128768,
  countries: 249,
  continents: 7,
  languages: 185
}

Calling the API:

Cities

This endpoint returns a list of cities (see City model below)

PATH:

/cities/
/countries/

Method:

GET

URL Params

  • Required:

    query=[url encoded string]
    
  • Optional:

    populate=[boolean] // defaults to true
    

Data Params

No needed

Success Response:

Code: 200 OK
Content: City[]

Error Response:

Code: 400 BAD REQUEST
Content: {"error": "No query provided."}

OR

  Code: 400 BAD REQUEST
  Content: {"error": "Too many results. Consider being more specific.", "matches": [integer]}
  • Sample Call:
$ curl -X GET "127.0.0.1:5000/cities/?query=sao+paulo&populate=false"
$ curl -X GET "127.0.0.1:5000/countries/?query=brazil&populate=true"

Search (search.py)

# input
> $ python ./search.py cities "sao paulo" true
# output
[
    {
        "_id": "5fa0b349b20d4824443f6c89",
        "name": "São Paulo do Potengi",
        "lat": "-5.895",
        "lng": "-35.76278",
        "country": "5fa08226bea7a74c5c69abfa"
    },
    {
        "_id": "5fa0b349b20d4824443f6f2e",
        "name": "São Paulo",
        "lat": "-23.5475",
        "lng": "-46.63611",
        "country": "5fa08226bea7a74c5c69abfa"
    },
    {
        "_id": "5fa0b349b20d4824443f73c0",
        "name": "São Paulo de Olivença",
        "lat": "-3.37833",
        "lng": "-68.8725",
        "country": "5fa08226bea7a74c5c69abfa"
    }
]
Elapsed time: 0.9119657

Examples (Schemas open to suggestions)

City

{
  "_id": "5fa0b349b20d4824443f6f2e",
  "name": "São Paulo",
  "lat": "-23.5475",
  "lng": "-46.63611",
  "country": "5fa08226bea7a74c5c69abfa"
}

Country

{
  "_id": "5fa08226bea7a74c5c69abfa",
  "currency": ["BRL"],
  "languages": ["5fa06fb848b4572eb409287b"],
  "name": "Brazil",
  "native": "Brasil",
  "phone": "55",
  "capital": "Brasília",
  "initials": "BR",
  "continent": "5fa07297a260950fb890031c"
}

Continents

{
  "_id": "5fa07297a260950fb890031c",
  "name": "South America",
  "initials": "SA"
}

Languages

{
  "_id": "5fa06fb848b4572eb409287b",
  "name": "Portuguese",
  "native": "Português",
  "initials": "pt"
}

Can't find your city?

Feel free to send a PR whenever you want

cities-api's People

Contributors

cicerotcv avatar cpyberry avatar itsabhianant avatar

Stargazers

Thalia Loiola avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

cpyberry thalials

cities-api's Issues

Search algorithm

The search algorithm seems to be quite inefficient. Should we consider using to a relational database?

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.