You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Arthur Poulet da57479f02 Merge branch 'master' into v0.2 4 years ago
config update structure 5 years ago
data Initial commit 5 years ago
db fix seeds 4 years ago
lib improv http header 5 years ago
src fix 4 years ago
.gitignore Initial commit 5 years ago
Changelog Merge branch 'v0.2' 5 years ago
DOCUMENTATION.md update structure 5 years ago
Gemfile update Gemfile 5 years ago
Gemfile.lock update Gemfile 5 years ago
LICENSE Initial commit 5 years ago
README.md update readme 5 years ago
Rakefile update structure 5 years ago
api_france fix seeds 4 years ago
api_france.rb fix seeds 4 years ago

README.md

ApiFrance

ApiFrance is a simple ruby application to serve an api with cities, regions, departments of France.

Configuration

Simply configure your db/database.yml.
Then, you can run the following commands rake db:init
It can take a while (+36k records).

Running

Then, run rake server and go to http://localhost:8080/cities?id=1 for example. Parameters are :

  • port <port> : port to use. Default is 8080

You can also go to the console and try your code with rake console

Api documentation

The api will return a Json like :

{
  "count" => nbr_of_results_total,
  "results" => [
    {
      "id" => id
      "name" => name
      ... => ...
    }
  ]
}

The “count” is without limit. An empty search will return count = maxium but limit the results by 1000 elements (by default)

”…” correspond to the values of the elements. There are :

  • cities id,name,zipcode,department_id,region_id,longitude,latitude
  • departments id,name,region_id
  • regions id,name

The api will not provide a full access to the data base. The number of result is basicaly limited by 1000. It can be configured in the configuration.yml

Api parameters

The api can scan 3 tables : cities, regions, departments. So, the request must begin with on of theses.

  • E.g : http://api.local.dom/cities?param=x&param2=y

The arguments can be a value of the tables :

  • E.g : http://api.local.dom/cities?id=1 will return the first city of the table (id = 1)
  • E.g : http://api.local.dom/department?name=var will return every department having their name = “var” (case insensitive)

Api special parameters

You are also allowed to do research on the api via the following arguments :

  • name_like : you can use this argument to do an advanced search through any table. The value of the parameter can have a ‘*’ or ‘?’ to replace (0+ / 1) other characters.
    E.g : http://api.local.dom/cities?name_like=pari?

  • id_lesser / id_greater : search using the id. It is lesser or equal (not strict). Same for greater.
    They can be combined.
    E.g : http://api.local.dom/regions?id_lesser=4
    E.g : http://api.local.dom/cities?id_greater=100&id_lesser=130

  • has_zipcode : when touching the cities table, this param will take every town having this zipcode. Muse be 5 digits length.
    E.g : http://api.local.dom/cities?has_zipcode=75001